Setting PictureData() to an URL

58 views
Skip to first unread message

Collection PhotoGraphex

unread,
Jun 24, 2020, 11:20:11 PM6/24/20
to SuperCard Discussion
Hello, 

I wonder if it would be feasible to set the graphic of a field, a JPEG file for instance, with the function PictureData() to a valid URL instead of an HFS file path?

This might be incredibly handy!

I can't find any reference for it in the SuperCard Help, nor in the User Guide. 

Many thanks for you help,  

André

codegreen

unread,
Jun 25, 2020, 5:06:00 AM6/25/20
to SuperCard Discussion
FWIW this isn’t hard to fake:

on url2pd imageURL, grcDesc

  local filePath = findFolder(userSpecificTempFolder) & createUUID(), it = shell(merge("curl -fo `[[hfsToPosix(filePath)]]` `[[imageURL]]`"))

  if exists(file, filePath) then

    set the pictureData of grcDesc to filePath

    delete file filePath

  else alert "Couldn't find that image:" explain imageURL

end url2pd


on test

  url2pd "https://www.gstatic.com/webp/gallery/2.jpg", "cd grc 1"

end test


-Mark

Collection PhotoGraphex

unread,
Jun 25, 2020, 9:18:32 PM6/25/20
to SuperCard Discussion
Hello Mark, 


Le jeudi 25 juin 2020 05:06:00 UTC-4, codegreen a écrit :
FWIW this isn’t hard to fake:

Nice, another demonstration of the flexibility and capability of the SuperTalk language!

Very, very good, It will do what I was wishing for! I'll put it right away on the test bench to tinker around it. 

Your suggestion do open the door for a new possibility for the project I am working on, as all the picture documents I am dealing with do have unique names, the randomization of the file name isn't necessary.  Better, the documents may be saved inside a temporary cache folder for pictures as they be needed repeatedly during a user session and can deleted later on. 

Would there be a way to apply scaling to the saved temporary picture document?

Thanks a bunch!

André

codegreen

unread,
Jun 26, 2020, 1:13:31 PM6/26/20
to SuperCard Discussion
What sort of scaling are we talking about here?

-Mark

codegreen

unread,
Jun 26, 2020, 4:52:41 PM6/26/20
to SuperCard Discussion
BTW it's probably worth noting for posterity that you can also download images asynchronously:

on test2

  lock screen

  global gTaskList

  local tURLProto = "https://www.gstatic.com/webp/gallery/[[i]].jpg", tFileProto = findFolder(userSpecificTempFolder) & "[[i]].jpg", tObjProto = "cd grc [[i]]"

  repeat with i = 1 to 5

    local tFile = merge(tFileProto), tObj = merge(tObjProto)

    set the pictureData of tObj to none

    put tab & bkgndTask("", "/usr/bin/curl", "-fo", hfsToPosix(tFile), merge(tURLProto)) & tab & tObj & tab & tFile & cr after gTaskList

  end repeat

  put "We're done with the synchronous part already!"

end test2


on bkgndTask taskID

  global gTaskList

  get lineOffset(tab & taskID & tab, gTaskList)

  if it 0 then

    set the itemDel to tab

    local tTask = line it of gTaskList, tFile = item 4 of tTask

    if exists(file, tFile) then

      set the pictureData of (item 3 of tTask) to tFile

      delete file tFile

    end if

    delete line it of gTaskList

    if gTaskList is empty then release gTaskList

  end if

end bkgndTask


HTH,
-Mark

sandro.bilbeisi

unread,
Jun 27, 2020, 5:37:47 AM6/27/20
to SuperCard Discussion
quick and dirty example project : 
Async Image download.sc45

Collection PhotoGraphex

unread,
Jun 27, 2020, 9:05:36 PM6/27/20
to SuperCard Discussion

Hello Mark, 

BTW it's probably worth noting for posterity that you can also download images asynchronously:

 You are reading into my mind! That will definitely be quite handy for preloading previews! 

I am adding this the the test bench!

Thanks a lot!

Collection PhotoGraphex

unread,
Jun 27, 2020, 9:20:14 PM6/27/20
to SuperCard Discussion
Hello Mark, 

What sort of scaling are we talking about here?

Most of the HTTP downloaded images will be of a much unnecessary too high resolution for the intended previews, if the picture documents, exclusively JPEGs averaging 1800x1800 pixels could be proportionally scaled down to 480x480 for the temporary cache folder storage, it would probably speed the general user's experience! I suppose! Especially that some images are of a much higher resolution, above 3600x3600 pixels and more. 

Regards

André

Collection PhotoGraphex

unread,
Jun 27, 2020, 9:23:05 PM6/27/20
to SuperCard Discussion
quick and dirty example project : 

Great demo, Sadro!

Thanks a bunch!

André

codegreen

unread,
Jun 28, 2020, 12:17:53 AM6/28/20
to SuperCard Discussion
You'll typically get the highest-quality result when scaling (especially non-proportionally) if you download the freeware command-line tool ImageMagick and use that, but if you're just trying to create quick thumbnails it's a pretty big hammer...

The simplest 'pure SuperTalk' way to do this is to set the pictureData of a graphic to the source image, adjust the graphic's rect to the desired thumbnail size, then export the card using its rect to a variable or another file and set the pictureData of the final object to that.

You'll probably want to do that scaling operation in another invisible window to avoid accidentally capturing any overlaying object(s).

This example (which you should be able to swap into Sandro's project) shows the general theory of operation for 'export to file' version, though you'd probably want to use a pre-made window if you were planning to do this a lot:

on test3

  put "Starting synchronous part..."

  global gTaskList

  put empty into gTaskList

  local tURLProto = "https://www.gstatic.com/webp/gallery/[[i]].jpg", tFileProto = findFolder(userSpecificTempFolder) & "[[i]].jpg", tObjProto = "cd grc [[i]]"

  lock screen

  lock messages

  push cd

  new inv wd

  new grc

  pop cd

  repeat with i = 1 to 5

    local tFile = merge(tFileProto), tObj = merge(tObjProto)

    set the pictureData of tObj to none

    put tab & bkgndTask("", "/usr/bin/curl", "-fo", hfsToPosix(tFile), merge(tURLProto)) & tab & tObj & tab & tFile & cr after gTaskList

  end repeat

  put "We're done with the synchronous part already!"

end test3


on bkgndTask taskID

  global gTaskList

  get lineOffset(tab & taskID & tab, gTaskList)

  if it 0 then

    set the itemDel to tab

    local tTask = line it of gTaskList, tFile = item 4 of tTask

    if exists(file, tFile) then

      local tThumbNailFile = thumbNail(tFile, 360, 360)

      set the pictureData of (item 3 of tTask) to tThumbNailFile

      delete file tFile

      delete file tThumbNailFile

    end if

    delete line it of gTaskList

    if gTaskList is empty then

      release gTaskList

      lock screen

      lock messages

      push cd

      open inv last wd

      delete wd

      pop cd

    end if

  end if

end bkgndTask


function fitRect adjRect, maxWidth, maxHeight

  local x = rectWidth(adjRect), y = rectHeight(adjRect), x_factor = maxWidth / x, y_factor = maxHeight / y, factor = min(x_factor, y_factor)

  put item 1 of adjRect + round(x * factor, up) into item 3 of adjRect

  put item 2 of adjRect + round(y * factor, up) into item 4 of adjRect

  return adjRect

end fitRect


function thumbNail imgPath, maxWidth, maxHeight

  local thumbPath = imgPath

  set the itemDel to "."

  delete last item of thumbPath

  put "_thumbnail.jpg" after thumbPath

  lock screen

  lock messages

  push cd

  open inv last wd

  set the pictureData of last cd grc to imgPath

  set the rect of last cd grc to fitRect(the rect of last cd grc, maxWidth, maxHeight)

  export cd from the topLeft of last cd grc to the botRight of last cd grc to jpeg file thumbPath

  pop cd

  return thumbPath

end thumbNail


HTH,
-Mark

Sandro Bilbeisi

unread,
Jun 28, 2020, 12:56:37 AM6/28/20
to superca...@googlegroups.com
again , a quick and dirty build with thumbnails set at 320x240

--
You received this message because you are subscribed to a topic in the Google Groups "SuperCard Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/supercard-talk/0ApuZuf0qd4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to supercard-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/supercard-talk/86a1eadb-6bef-4916-b5d4-937fe6115490o%40googlegroups.com.
Async Image download thumbnailer.sc45

sandro.bilbeisi

unread,
Jun 28, 2020, 7:29:37 AM6/28/20
to SuperCard Discussion
It is possible to use Liyanage's CoreImageTool instead of something massive (albeit featurefull) as ImageMagick

CoreImageTool has functionality to Crop , resize and filter , distort and export images with tons of CoreImage filters




I am experimenting right now with the default CILanczosScaleTransform scaling algorithm
./CoreImageTool load pic /Applications/SuperCard\ 4.81/gstatic1.jpg filter pic CILanczosScaleTransform scale=0.5 store pic gstatic1_tn.jpg public.jpeg
 
it seems to work very well
I will post an example project ASAP

On Thursday, June 25, 2020 at 5:20:11 AM UTC+2, Collection PhotoGraphex wrote:

Collection PhotoGraphex

unread,
Jul 2, 2020, 10:06:59 PM7/2/20
to SuperCard Discussion

BTW it's probably worth noting for posterity that you can also download images asynchronously:

Thank you Mark, I can “picture” in my mind where I am going to use your suggestion in a short future to preload all potential previews for a record!

Regards

André 
Reply all
Reply to author
Forward
0 new messages