Ritashugisha Posted February 10, 2014 Share 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 Link to comment
rice.shawn Posted February 10, 2014 Share 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. Link to comment
rice.shawn Posted February 10, 2014 Share 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. Link to comment
jdfwarrior Posted February 10, 2014 Share 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. Link to comment
horizens Posted January 25, 2017 Share 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; } Link to comment
deanishe Posted January 26, 2017 Share Posted January 26, 2017 (edited) 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. Edited April 13, 2021 by deanishe Update URL Link to comment
Alan He Posted January 6, 2021 Share Posted January 6, 2021 How to trigger re-run the Script Filter? For example, how do I trigger in a JS. On 1/26/2017 at 5:39 PM, deanishe said: 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. Link to comment
deanishe Posted January 6, 2021 Share Posted January 6, 2021 4 hours ago, Alan He said: How to trigger re-run the Script Filter? For example, how do I trigger in a JS. What do you mean “in a JS”? You can only tell Alfred to rerun a Script Filter from its own feedback JSON. Link to comment
Alan He Posted January 7, 2021 Share Posted January 7, 2021 20 hours ago, deanishe said: What do you mean “in a JS”? You can only tell Alfred to rerun a Script Filter from its own feedback JSON. What's the feedback JSON ? Can you post a link or example? What do you mean “in a JS”? means in a Run Script step. Link to comment
Mr Pennyworth Posted January 7, 2021 Share Posted January 7, 2021 1 hour ago, Alan He said: What's the feedback JSON ? Can you post a link or example? https://www.alfredapp.com/help/workflows/inputs/script-filter/json/ Search for "Rerunning script filters automatically" on that page Alan He 1 Link to comment
deanishe Posted January 7, 2021 Share Posted January 7, 2021 5 hours ago, Alan He said: What do you mean “in a JS”? means in a Run Script step Not possible. It's a Script-Filter-only feature. Link to comment
giovanni Posted April 13, 2021 Share Posted April 13, 2021 On 1/26/2017 at 4:39 AM, deanishe said: 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. Hello, does this script live somewhere else? thanks! Link to comment
deanishe Posted April 13, 2021 Share Posted April 13, 2021 1 hour ago, giovanni said: Hello, does this script live somewhere else? thanks! https://git.deanishe.net/deanishe/alfred-unwatched-videos/src/branch/master/src/thumbnails.py I thought I had that redirected. Hmm. giovanni 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now