When processing an image through ImageAPI Optimize virtual toolkit and using as destination Amazon S3 (using s3fs module), image will get saved directly to s3fs without ever running through the optimizers. Tried with png image + optipng.

A debugging session showed that image_gd_save() will put the image in s3, then image_imageapi_optimize_save() will get a URL with 's3://' stream wrapper for $dst. Calling drupal_realpath() on that URL won't return a valid path/URL. This means ImageAPI Optimize doesn't support stream wrappers. Yet ;).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jedihe created an issue. See original summary.

jedihe’s picture

Status: Active » Needs review
FileSize
1.36 KB

image_gd_save() uses a workaround to properly support remote stream wrappers. I just took the code handling that and transplanted into image_imageapi_optimize_save(). Quick testing showed it working just fine (optipng, with an image style not applying any effect to just get it going through the pipeline).

Patch is attached.

Steven Jones’s picture

Status: Needs review » Needs work

This is pretty cool!

Needs a little clean up, because we can ignore the $success return value from our attempt at saving I think.

  • Steven Jones committed 2d65789 on 7.x-1.x authored by jedihe
    Issue #2759277 by jedihe: Images won't be optimized when used with s3fs
    
  • Steven Jones committed 72c58fc on 7.x-1.x
    Issue #2759277 by Steven Jones: Images won't be optimized when used with...
Steven Jones’s picture

Status: Needs work » Fixed
Vacilando’s picture

This may be needed for 7.x-2.x — or isn't it?

Steven Jones’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Fixed » Patch (to be ported)

@Vacilando Yep, spot on. We have the same issue in 7.x-2.x.

Steven Jones’s picture

And likely 8.x-2.x too.

Steven Jones’s picture

For 7.x-2.x I think we should modify imageapi_optimize_optimize_file so that if the file is in a remote filesystem we copy it to the temporary one, then let the processors process, and then save it back to the remote filesystem after all processing.

Some of the processors could probably copy with being passed a remote file and still work fine, but it's probably an implementation detail best hidden from them.

Steven Jones’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.55 KB

Something like this.

Steven Jones’s picture

Could really do with testing this out.