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.
It seems that when optimization happens (tried with reSmush.it) the module overwrites the original (large) image with its optimized (smaller) version -- correct?
This can be a problem for those users who happen to have their original images in the files folder and they rely on them not being tampered with.
It can also be problematic for those sites that reuse their images for other purposes. It is always wiser to resize, crop, or otherwise manipulate the original images, and only then optimize them.
Or am I being too fussy? :-)
Comment | File | Size | Author |
---|---|---|---|
#10 | optimize_target_image-2893046-10.patch | 1.41 KB | SpaghettiBolognese |
Comments
Comment #2
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedIt's possible that the 7.x-1.x branch is optimizing your uploaded images.
7.x-2.x implements this functionality in a different way so that it only optimizes generated images, which is as you suggest best practice.
I'm aiming to clean the branch up and get an upgrade path in place in the next few weeks!
Hope that helps.
Comment #3
Vacilando CreditAttribution: Vacilando as a volunteer commentedWell in fact I looked at 7.x-2.x -- there too the sources are being overwritten.
See
file_unmanaged_save_data($result->data, $dst, FILE_EXISTS_REPLACE);
in http://cgit.drupalcode.org/imageapi_optimize/tree/plugins/imageapi_optim...There, $dst is just drupal_realpath() of the original file's location in the files folder.
Comment #4
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedAh yeah, absolutely.
The file is generated by Drupal from the original image, applying an image style or whatever, and then we optimise and replace that generated file.
We avoid replacing the very original source image.
Comment #5
jcisio CreditAttribution: jcisio at Axess Open Web Services commentedThen it's a problem with the 2.x branch. In 1.x branch, we only optimize when the image is save after all effects being applied, i.e. it's the derivative.
Comment #6
jcisio CreditAttribution: jcisio at Axess Open Web Services commentedPS: I reopen because I think it's problematic optimizing (even lossless) the original image. Besides, we are going to introduce some lossy optimizer (e.g. Google's guetzli).
Critical because there is data loss.
Comment #7
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commented@jcisio I'm struggling to see where the data loss is here? Especially in the 7.x-2.x branch.
The 7.x-2.x branch is even more conservative with the images that it will 'overwrite' than 7.x-1.x.
7.x-2.x provides an API for optimising an image 'in place', overwriting the existing image. It then uses that API when generating image styles to optimise the derivative image. I don't see this is problematic data loss? Drupal core provides a UI for deleting all these images, so the data loss of these images can't be a problem.
Fundamentally there's a misunderstanding here, imageapi_optimize has always replaced the image it passes to the optimisers:
http://cgit.drupalcode.org/imageapi_optimize/tree/services/resmushit.inc...
It's just that most of the time in 7.x-1.x and all of the time in 7.x-2.x that image passed to the optimisers is already generated and not the same as the very originally uploaded source image.
Comment #8
jcisio CreditAttribution: jcisio at Axess Open Web Services commentedYou're correct. I've checked the 2.x code and it seems that it still does in the same way (all the stuffs done in
image_imageapi_optimize_save()
when it is invoked usingimage_toolkit_invoke('save', ...)
). No optimization happens for uploaded files. Maybe the OP misconfigured the image field to resize the uploaded image and optimization happened? In that case I'd say that it is expected behavior.I don't close this issue because we need some confirmation about that. I've also open #2893186: Update README because README file has not been updated for 5 years.
Comment #9
Vacilando CreditAttribution: Vacilando as a volunteer commentedIndeed, the 7.x-1.x was always overwriting the source images.
But doesn't 7.x-2.x do the same? See http://cgit.drupalcode.org/imageapi_optimize/tree/plugins/imageapi_optim...
Comment #10
SpaghettiBolognese CreditAttribution: SpaghettiBolognese at Emble commentedFor whoever is interested: here is a patch for the 7.x-1.x branch which adds the option to only optimize imagestyles.
Comment #11
garbo CreditAttribution: garbo commentedHi, I'm reading this thread and I'm getting worried.
With Image Optimize v7.1.3, is it the original uploaded image that is being optimized or is it the derivative image style that is being optimized?
If it is the first, than this module is an absolute no-go for me. I want to be able to keep the original unoptimized images since you never know if a new and better optimization toolkit will become available in the future.
Thanks in advance for any reply on my question.
Comment #12
dddbbb CreditAttribution: dddbbb as a volunteer commentedThanks for the patch in #10.
Comment #13
dddbbb CreditAttribution: dddbbb as a volunteer commentedComment #15
guardiola86 CreditAttribution: guardiola86 commentedPatch works but I don't see any massive improvement in file size reduction.