Cropping a referenced image

Stephen MacLean smaclean at madmansoft.com
Tue Aug 14 12:18:10 EDT 2018


> 
> 
> #test
> 
> on mouseup
> 
> put the long id of img "thumbTemplate" into pImage
> 
> put the loc of pImage into pLocation
> 
> set the filename of pImage to "https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg"<https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/default.jpg>
> 
> 
> --set the filename of pImage to "https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg"<https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg><https://i.ytimg.com/vi/KO3l3-4pFyo/hqdefault.jpg>
> 
> set the loc of pImage to pLocation
> 
> end mouseup
> 
> USE CASE:
> 
> 1) eliminate top and bottom letter boxing on YouTube thumbnails. Easy done on web with CSS, not easy in LC
> 2) They provide a 4x3 by ratio
> 3) But when you post an HD video, thumbnail is 16x9, letterbox, top and bottom (45 pix of the hqdefault.jpg).
> 4) All youTube video channel thumbnails are letterboxed -- we don't 4X3 videos, ever...
> 6) "crop" command does on work with referenced images.
> 7) Look for a simple method that in the data grid takes up very little CPU time.
> 8) options
>     a) seems like I could make a mask on top the image to eliminate the letterbox.
>     b) other options?
> 9) we could go to the trouble to down load the thumb and crop and store them in /documents (mobile app); but there's no point: the user *has* to have a internet connection to use this module to view YouTube; and the call to https://i.ytimg.com is very fast, so why bother?
> 
> Spotify does a similar thing: it has a generic icon until the album cover is loaded.
> 
> Any ideas?  Meanwhile I'll explored masking.
> 
> BR


Hi BR,

I’ve had problems with "set the filename of pImage to” and use a slightly different method (In a nutshell):

on a card (cropImg), I have a blank image for loading the image into (checkImg) and a rectangle set to the size I want to crop (cropRect).

First, put get the image and put that image into your blank (I do use tsNet directly to do this, as it seems to be the most reliable, even though the URL library uses tsNet:

put URL tURL into tempImage
put tempImage into image "checkImg" of card "chkImg"

In script I position the crop rectangle over the image the way I want it.

Next, export the image inside the cropRect:

put the long ID of grc "cropRect" of cd "cropImg" of stack "imgEngine" into cropRectID

put the long ID of img "checkImg" of cd "cropImg" of stack "imgEngine" into checkImgID

# Export the cropped image

set the text of checkImgID to empty

export snapshot from rect (rect of cropRectID) of checkImgID to tTempCrop as JPEG

set the text of heroImgID to tTempCrop


From there you can save it or do whatever else you want to do:)

HTH,

Steve MacLean


More information about the use-livecode mailing list