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

peterx’s picture

A 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:

module_invoke_all('imagefield_crop_resize_before', $image);
$result = $result && image_save($image, isset($dst_file->uri) ? drupal_realpath($dst_file->uri) : $src);
module_invoke_all('imagefield_crop_resize_after', $image);

The other changes might be achievable through hook_form_alter() etc.