When an image is pulled in from Flickr, it is copied and a local thumbnail is created (this local thumbnail is used, e.g., for creating image styles). However, this process is done entirely outside of the managed file workflow - the thumbnail is sitting in the local files directory but the rest of Drupal doesn't know about it. Meanwhile, Media Flickr is based off the Media Internet module's MediaReadOnlyStreamWrapper class, which is for read-only remote files and knows nothing about the local file either.

This leads to several issues:

  1. I want to make Flickr images work with the ImageField Focus module, but they currently don't. That's because the image filters provided by that module rely on being able to load the original file object by URI (based on the URL that is visited when the image style is generated) but in the case of Media Flickr there is no such relationship.
  2. If you try to get any information from the Flickr image by calling image_get_info() on the flickr:// URI, it doesn't work. (This also comes up in the ImageField Focus integration.)
  3. If you do anything which calls image_path_flush() on the Flickr image, it won't actually clear any of the cached image derivatives that were generated from the local thumbnail, and thus the site will continue to serve outdated image derivatives.
  4. (There are probably more that I didn't run into.)

I propose to switch the Media Flickr module to use a local stream wrapper instead, which is fully aware of both the original Flickr image (external URL) as well as the local thumbnail image.

The patch in this issue achieves the above and seems to work well on a fresh site. (And with the patch, the ImageField Focus module now works fine with Media Flickr.)

One caveat, though, is that for existing sites that already have Flickr images there will be problems; to fix those, there would need to be an update function to clear out existing image styles (their location has moved) and make sure the original thumbnail is downloaded for all Flickr images already on the site.

Another caveat is that Flickr images don't have a .jpg extension anymore after this patch is applied. That is cosmetic only, as far as I know, so not a big deal. I wanted to preserve it, but didn't see any way to do so without changing the Flickr URIs as well (i.e., we'd have to store URIs like flickr://u/xxxxx/p/xxxxxxxxxx.jpg rather than flickr://u/xxxxx/p/xxxxxxxxxx).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Status: Active » Needs review
FileSize
7.93 KB

Here is the patch.

David_Rothstein’s picture

Also, if you happen to be using the Stage File Proxy module on the development version of a site that uses this patch, you'll need #2049807: Local image styles aren't found for stream wrappers that aren't on the top level of the public files directory also.

David_Rothstein’s picture

Another caveat is that Flickr images don't have a .jpg extension anymore after this patch is applied. That is cosmetic only, as far as I know, so not a big deal.

Although modern browsers can handle this with no problem, it does appear that some web servers will balk if you try to visit the image URL directly (offer you to download it rather than displaying it as a jpg). So this may need to be fixed.

I still think the patch here is an overall good direction, but for the project we were going to use this on we're taking a different direction instead. See the Media Flickr Local sandbox project I just posted today.

liquidcms’s picture

hey Dave, any update on your sandbox project?

liquidcms’s picture

patch seems to work.. you da man Dave!!

i noticed that the local file storage is not where the file field setting is i set as images/flickr but it has added in files/media-flickr.

rodrigoaguilera’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll