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
FWIW this isn’t hard to fake:
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
BTW it's probably worth noting for posterity that you can also download images asynchronously:
What sort of scaling are we talking about here?
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
--
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.
./CoreImageTool load pic /Applications/SuperCard\ 4.81/gstatic1.jpg filter pic CILanczosScaleTransform scale=0.5 store pic gstatic1_tn.jpg public.jpeg
BTW it's probably worth noting for posterity that you can also download images asynchronously: