Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
i'm developing a site that uses external pictures on other servers. pictures come from different sources and have different sizes.
i would like to pull the images and use imagecache and then safe a local copy of the image for next time the file is requested.
any idea how to handle remote files with imagecache?
Comment | File | Size | Author |
---|---|---|---|
#30 | get_remote_image.zip.txt | 3.95 KB | swill |
#5 | imagecache-remote.patch | 3.41 KB | burgs |
#4 | imagecache-remote.patch | 2.77 KB | burgs |
Comments
Comment #1
dopry CreditAttribution: dopry commentednot a feature of imagecache. you'll have to do some coding to get that working.
Comment #2
taqwa CreditAttribution: taqwa commentedWere you able to figure out how to do this?
Comment #3
Jomel CreditAttribution: Jomel commentedThis interests me too - I'm aggregating external feeds, and it would be really nice if I could just output resized copies of their images using the same theme('imagecache',...) I use for local images.
Comment #4
burgs CreditAttribution: burgs commentedThis is a small patch, that doesn't respect a whole lot of the imagecache functionality: It doesn't deal with private files, and if the external image doesn't exist it will WSOD, i think.
It does however, cache the external image locally, then cache the preset version. So, it should only call externally once per image.
Patch is on version 5.1.6
To use, just use
Comment #5
burgs CreditAttribution: burgs commentedOk, here's a better patch. It still needs some work.
Same instructions as above.
Comment #6
Eidolon NightIs this feature available in 6.x-2.0-beta5 ?
Comment #7
drewish CreditAttribution: drewish commentedtotally not a fan of this approach. i'd be into a separate module that handled the fetching and storage and then handed them to imagecache but i don't see any reason to complicate imagecache.module with that functionality.
and it'd have to happen in the latest version.
Comment #8
burgs CreditAttribution: burgs commentedI agree, the patch i did screams of hack, and it breaks with urls with query strings etc. I am using it on a site though, with some fixes for query strings, and it's some of the best functionality ever. It's really handy.
Simon
Comment #9
nedim.hadzimahmutovic CreditAttribution: nedim.hadzimahmutovic commentedIs there a way to get http://drupal.org/project/get_image and http://drupal.org/project/remote_file to work together? :)
Comment #10
nedim.hadzimahmutovic CreditAttribution: nedim.hadzimahmutovic commentedThis could be done with remote_file and cck - http://drupal.org/node/375549
Comment #11
drupalninja99 CreditAttribution: drupalninja99 commentedOne solution as a "bridge" is to have your own function to fetch the image locally and then use imagecache's existing functionality.
I have an MLS search with all remote images and I want to use them with imagecache. So I make my custom module fetch the image if it doesn't exist. If it does exist it returns the filepath for my imagecache call and voila we've got it. That means the first time an image is downloaded its a bigger hit. It also means I have a file check every time I look at an image. And it means I'm going to download alot of these images on my file system. So performance may be an issue here but for now I like it. Here's my function:
Comment #12
OnkelTem CreditAttribution: OnkelTem commentedThank you for the patch, burgs!
I was looking for such functionality to get emfield videos thumbnails to go through imagecache. I created a simple module which brings imagecache display options to video_cck and applied your patch. Now remote images work fine.
After investigations I found two drawbacks in your patch:
1) error in function imagecache_create_url($presetname, $path):
if (stripos($path, 'http://') === 0){ -- correct variant, with three '='s, not two
2) paths to imagecached images should be urlencoded too, otherwise all image links are processing through imagecache's transfer instead of simply be retrieved via direct link.
Quick solution: $path = 'http/'.urlencode(str_ireplace('http://', '', $path)) in imagecache_create_url.
Full function code (DRUPAL 5):
Needs testing though
Comment #13
swill CreditAttribution: swill commentedIn general I hate hacking modules or core. I ran into this same issue, so I wrote the following function in one of my modules to take care of the issue. Enjoy...
Comment #14
drupalina CreditAttribution: drupalina commentedSubscribing.
I have a Digg-like site powered by Drupal 5.12 and Drigg_5x_1.36. Users submit links. If they want they can upload an image with Imagefield, which is handled by Imagecache, but this is a very "slow" solution (users need to download an external image, and then upload it, and then there are whole lot of copyright issues). What would be absolutely awesome is when users submit a link and while they're still on the "submit" form, a query goes out to that particular URL page and dynamically brings a set of images from that external URL, which are resized by Imagefield and immediately presented for the user to choose from. We see this kind of functionality in action on Digg.com and also on Facebook when we attach a link. My question: will any of the above patches and codes provide this kind of solution???
I really appreciate your help!
Comment #15
Finn Lewis CreditAttribution: Finn Lewis commentedThanks swill - Just what I was looking for. The code in #13 worked for me (on Drupal 6.10, Imagecache 6.x.2.0-beta8).
Comment #16
swill CreditAttribution: swill commentedecofinn, thanks for confirming the code in #13 works for you. :)
Comment #17
mkalbere CreditAttribution: mkalbere commentedHi ...
just to make it a bit more generic :
Comment #18
parrottvision CreditAttribution: parrottvision commentedsubscribing
Comment #19
sonictruth CreditAttribution: sonictruth commentedCheck out my blog post about doing this to pull in images from Flickr and run them through Imagecache.
http://marmaladesoul.com/using-imagecache-external-images
I'm thinking about making it more generic and turning it into a module.
Comment #20
mark_r CreditAttribution: mark_r commentedSubscribe. That is exactly what i'm looking for! :) Now, reading the thread.
Comment #21
swill CreditAttribution: swill commentedThe code in #13 with the update in #17 is probably your best bet...
Comment #22
ChrisRut CreditAttribution: ChrisRut commentedSubscribe
Comment #23
zeezhao CreditAttribution: zeezhao commentedsubscribing
Comment #24
drupalninja99 CreditAttribution: drupalninja99 commentedOne thing to note, I have found caching remote images is too slow for my site which downloads a lot of MLS listings for TN. I ended up resizing the images in CSS bc the time it takes to download the image and cache it was too long. It might be worth it for sites where image content isn't constantly updated like it is on an MLS site.
Comment #25
swill CreditAttribution: swill commentedThat is a very good point. The function that I wrote in #13 (with the improvement in #17) is going to be quite slow when it gets the images for the first time (especially if you are getting lots of them). If the images that you are getting well be changing all the time and you are not reusing the saved images more than 75% of the time, this approach is probably not going to work for you.
In my case, I had to find a way to get the images initially and then reuse the images that I got from then on. I needed to make sure that if an image was changed remotely, that my application what dynamic enough to see that the image had changed and update itself.
Comment #26
Garrett Albright CreditAttribution: Garrett Albright commentedInteresting to see this issue - I am currently suffering from Geek Ego (you know, that feeling you get when you've done something amazing but very few other people in the would have the capacity of understanding its greatness) because I've managed to pull this off successfully, and without hacking ImageCache or anything else. It's a kludge, and not for the feint of heart, but it works. Here's some basics on my plan of attack:
The first problem is that I wanted my images to be attached to nodes via a CCK ImageField/FileField, but FileField cannot attach files to nodes if the files don't actually exist yet. So my code (which programmatically creates nodes) attaches a blank placeholder JPEG; one white square pixel, 304 bytes. (Pre-fetching the images wasn't really an option since this code will sometimes create 20,000 nodes at a time, and each listing could have dozens of images… The ideal solution is to download them as the user tries to view them, so that the fetching is spread out over time.)
The second problem is getting the new image when it's time to view it. To do this, I created a new ImageCache action (see the imagecache.api.php and imagecache_actions.inc files) which, when triggered, checks to see if the image it's being asked to act upon is one of those placeholder JPEGs; it runs a regex on the filename and checks if $image->info['file_size'] === 304. If it's a match, it downloads the new image, replaces the placeholder image with the new image, and updates the filesize of the image in the {files} table. It then tweaks the $image object as mentioned in #623770: _imagecache_apply_action(): Explicitly receive $image by ref?.
Hopefully circumstances will let me release this and the other code involved with this module soon…
Comment #27
reformatt CreditAttribution: reformatt commentedits quite the hack burgs!
but this remote imagecache patch was exactly what I was looking for.
My webserver was full and I had to move my images to another file server and this was a great quick fix!
Thanks again for the patch!
Comment #28
giorgio79 CreditAttribution: giorgio79 commentedThis seems to be promising:
http://drupal.org/project/get_image
It seems this wont happen in Imagecache and it wont happen in Filefield sources either:
#712866: Periodical refresh of remote file
Comment #29
scotjam CreditAttribution: scotjam commentedFYI...
Garret's posted his code referred to in #26 here
http://drupal.org/project/pirets
Comment #30
swill CreditAttribution: swill commentedI get a bunch of emails about this post because of the code I wrote in #13, so I cleaned it up and added the code by mkalbere from #17 and put it together as a little drupal 6 module (changing it to drupal 5 would just include changing the .info file).
The function I wrote is meant to be used in code, but it could also be used in the UI if you allowed PHP code entered in the UI (only do this if you are the only person you give access too).
Usage example if you use the PHP Code input format would be:
(NOTE: Be sure to change 'present_name' to the name of an imagecache present name you have setup on your site.)
(NOTE: You should only ever reference the url, if you already have the image, it will serve the local version.)
Thats it. I hope this help some people out.
Take note of #25. This function is great if you need to get the image once and then just use the local copy from then on. If you will be getting new images each time, this may not be the best option, but a good option is going to be difficult to come by. (You could just run this function in a cron job over all of the images you wanted to get so you would just reference the local image when you did your actual display to the user. I will leave that as an exercise if you need to make the download process faster because you are always referencing new images.)
Comment #31
NicolasH CreditAttribution: NicolasH commentedsubscribe
Comment #32
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #33
alberto56 CreditAttribution: alberto56 commentedFor those interested, here is a post on using imagecache with flickr images:
http://marmaladesoul.com/using-imagecache-external-images
Cheers,
Albert.
Comment #35
Stalski CreditAttribution: Stalski commented@alberto56: Your page is not working. I would like to see your solution.
Comment #36
alberto56 CreditAttribution: alberto56 commented@Stalski looks like the site's owner removed the content. Here is a cached version from Google, but it might not last long.
Comment #37
sovarn CreditAttribution: sovarn commentedI did a hacked solution to this problem for my site:
http://drupal.org/node/871144
using the flickr module and imagecache I was able to download the image then use imagecache to resize it.
Comment #38
NicolasH CreditAttribution: NicolasH commentedI think the official solution to this is http://drupal.org/project/filefield_sources.
Re-open if you disagree.
Comment #39
zilverdistel CreditAttribution: zilverdistel commented@NicolasH: I can't imagine how you would do something like
with the module you mention (filefield_sources). Also it depends on the module filefields and only works if you use cck.
Reopening ...
Comment #40
NicolasH CreditAttribution: NicolasH commentedIs there a good reason why you would not want to use filefield (and in fact Drupal's core file system)? And use CCK formatters to configure your presets, then have a simple variable available that contains the output in the tpl file, like $my_image_rendered? No further theme layer logic required and no hardcoded presets.
Sure, short-circuiting/bypassing all those great systems works, but what is the advantage? You're also missing out on a lot of opportunities to keep your file system sane...
Comment #41
zilverdistel CreditAttribution: zilverdistel commentedI'm writing a views 3 query plugin that pulls and displays data from a REST-api. I want to re-use the imagecache theming for displaying fields with images. Since I'm not working with nodes, I certainly can't use cck.
Comment #42
glass.dimly CreditAttribution: glass.dimly commentedI've used the module image resize filter in certain contexts to solve this problem, but it'd be nice if this were handled by imagecache.
Comment #43
dan_lennox CreditAttribution: dan_lennox commentedDumping a basic D7 version of #13
Comment #44
alexharries CreditAttribution: alexharries commented@swill: thank you; this function has saved me an awful lot of time, and helped me a great deal!
Many thanks!
/al
Comment #45
mr.j CreditAttribution: mr.j commentedhttp://drupal.org/project/imagecache_external
Comment #46
fizk CreditAttribution: fizk commentedUse the ImageCache External module: http://drupal.org/project/imagecache_external