Ritashugisha 26 Posted February 10, 2014 (edited) Hey guys, quick question. Is there any easy way to use an image from a URL as the icon for a script filter? I've been downloading about 50 compressed thumbnails everytime I use a script I've been writing. (extremely slow) Do you guys know of any easier way to get images from a URL as a script filter icon? Thanks Edited February 10, 2014 by Ritashugisha Share this post Link to post
rice.shawn 216 Posted February 10, 2014 Alfred won't take the url as a file source. So, make your workflow have it's proper data directory, then download the images to that directory. Then, when you're loading them, do something like -- if cached file does not exist download new file into data directory; icon url = cached file. It makes it so that you'll still need to download them (there is no way around that), but it makes subsequent uses of the workflow faster. Share this post Link to post
rice.shawn 216 Posted February 10, 2014 Oh, if you'd rather not keep them around forever, then you might want to store them in the caches directory. That one should be cleared with every system cache clear. Share this post Link to post
jdfwarrior 287 Posted February 10, 2014 Hey guys, quick question. Is there any easy way to use an image from a URL as the icon for a script filter? I've been downloading about 50 compressed thumbnails everytime I use a script I've been writing. (extremely slow) Do you guys know of any easier way to get images from a URL as a script filter icon? Thanks Oh, if you'd rather not keep them around forever, then you might want to store them in the caches directory. That one should be cleared with every system cache clear. Shawn is correct. This is the current method for using remote images as icons. Remote icons would be nice to have but it very much affects performance. The Plex workflow I had been tinkering with hehe.. it was downloading LOTS of icons from another machine on my network and it was still pretty dang slow. Share this post Link to post
horizens 0 Posted January 25, 2017 This is the solution I came up with. It's definitely slow on the initial load, but once a thumbnail is saved, it's pretty fast. I'm using the workflows.php class: function registerResult($result) { global $w; $filename = 'thumbs/' . $result["objectID"] . ".jpg"; if(!file_exists($filename)) { $image = imagecreatefromjpeg($result["thumbnail"]); $thumb_width = 75; $thumb_height = 75; $width = imagesx($image); $height = imagesy($image); $original_aspect = $width / $height; $thumb_aspect = $thumb_width / $thumb_height; if ( $original_aspect >= $thumb_aspect ) { // If image is wider than thumbnail (in aspect ratio sense) $new_height = $thumb_height; $new_width = $width / ($height / $thumb_height); } else { // If the thumbnail is wider than the image $new_width = $thumb_width; $new_height = $height / ($width / $thumb_width); } $thumb = imagecreatetruecolor( $thumb_width, $thumb_height ); // Resize and crop imagecopyresampled($thumb, $image, 0 - ($new_width - $thumb_width) / 2, // Center the image horizontally 0 - ($new_height - $thumb_height) / 2, // Center the image vertically 0, 0, $new_width, $new_height, $width, $height); imagejpeg($thumb, $filename); } $w->result( $result["name"], $result["objectID"] . "---" . $result["canonicalUrl"] . "---" . $result["state"], $result["name"], $result["objectID"] . " - " . $result["state"] . isset($result["prices"]) ? " - " . money_format('$%i', $result["prices"]["final"]) : "", $filename ); return; } Share this post Link to post
deanishe 885 Posted January 26, 2017 Here is a fast(-feeling) way. Instead of waiting for missing images, it handles them in a background process and tells Alfred to re-run the Script Filter after 1 second. This class generates thumbnails, but the principle is the same as caching remote URLs. Generate Alfred results and add any missing images to a queue At the end of your Script Filter, if there's a queue, start a background process to handle it If the background process is running, tell Alfred to re-run the Script Filter in a second Exit Script Filter Obviously, the results come up image-less until the images have been cached, but it keeps the workflow super-responsive, and Alfred 3.2's re-run feature seamlessly reloads the results as the images come in. Share this post Link to post