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.
I am switching a site from Image to Imagefield Crop. There is a need to alter the JPEG compression per image for some images. Imagefield Crop could be changed to handle a JPEG compression setting. If Imagefield Crop had the right hooks, the bulk of the change could be a separate module. If someone works on a separate module and submits a patch to add hooks, would they be accepted?
Comments
Comment #1
peterx CreditAttribution: peterx commentedA note on why the change to compression is painful. The image eventually goes through image_gd_save() to the PHP imagejpeg() function. The image is passed as an object with attributes to alter the save. imagejpeg() overrides the JPEG compression through a separate parameter. image_gd_save() gets the JPEG compression setting from a variable.
To override the core image_gd_save() function, the variable has to be changed before calling image_gd_save() then changed back immediately after the call.
image_gd_save() is called by image_save(), which is called by _imagefield_crop_resize(). To make the change in an external module, the following code would need some help.
$result = $result && image_save($image, isset($dst_file->uri) ? drupal_realpath($dst_file->uri) : $src);
The help could be two hooks:
The other changes might be achievable through hook_form_alter() etc.