What do you think of providing the possibility to allow other modules to alter the quality settings?
At the moment it is using the global options.

$args['quality'] = '-quality ' . escapeshellarg(variable_get('imagemagick_quality', 75));

but lets say you have overview pages with tons of thumbnails and you want these to be compressed with 50%, but you want the bigger images to be 100%. An example for this would be an image database or a shop system.

Comments

sun’s picture

Good idea - although this requires each image style (or effect?) to (optionally) supply the quality.

http://drupal.org/project/modules?text=imagemagick reveals among others:

http://drupal.org/project/imagecache_quality
http://drupal.org/sandbox/dokumori/1310444

Could that idea be merged into the imagemagick_advanced sub-module?

marcoka’s picture

Assigned: Unassigned » marcoka

some notes, minds.
as far as i analyzed/worked out the logic, core would still need the patch:
#1310452: Allow to override the image toolkit's global JPEG/PNG quality value

not the full patch, because we could skip the gd patch part here. but we need that to actually get the style so we can get the custom set quality.
http://screensnapr.com/v/af8t5q.jpg

marcoka’s picture

ok my first suggestion. two patches.

1.) adds the ability to add a custom quality setting per preset
http://screensnapr.com/v/iHk4G2.jpg

2.) Is a patch for includes/image.inc and modules/image/image.module
passing through the $styles array, so one could get the settings of the style (image quality field) and replace it inside $args of imagemagick.

i have no idea how to do it without patching core. whats your opinion sun? any other suggestions?

sun’s picture

Title: Image quality » Custom image quality support
Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Status: Active » Needs work
Issue tags: +Image system

Unfortunately, I don't really have time to look into this right now.

However, I can't believe that this requires to patch core. Especially, because the quality parameter is set and contained in imagemagick.module, so its value is under our authority.

marcoka’s picture

StatusFileSize
new5.47 KB

No rush, i post what i got and if you have time you can look at it.

You were right, no core patch required. So to the new idea (thx to blackice).

The idea i followed now is adding the custom quality to the image object $image:

function imagemagick_advanced_quality_effect($image, $data) {
  $image->custom_quality = $data['quality'];
}

To alter the quality i had to pass the $image trough to imagemagick_advanced_imagemagick_arguments_alter(&$args, $context, $image)
so here i used the custom quality to alter the global quality.

marcoka’s picture

Status: Needs work » Needs review
sam152’s picture

This has been addressed without the use of any core hacks or work arounds in a clean and simple module.

Download Image Style Quality

marcoka’s picture

DHSamB, question is, is your module working for imagemagick or gd or both?

sun’s picture

Status: Needs review » Needs work

I've looked at the code of that Image Style Quality module, and I'm pretty confident that it will cause major problems.

Anyway, I actually think this could be directly added to Drupal core, so I've rolled an entirely new patch in:

#1310452: Allow to override the image toolkit's global JPEG/PNG quality value

At least the $image->quality tweak that essentially allows to override the quality could be backported to D7 (unless the whole thing can be backported).

sam152’s picture

sun, can you please elaborate on the major problems the module is likely to cause?

Thanks.

fietserwin’s picture

I fixed it in the imagecache_actions module for the "change file format" effect that also allows to define the quality. Unfortunately, it won't work for GD as that indeed needs a core patch. However, for imagemagick it would have been easier if the default quality is added at the beginning of the processing (image_imagemagick_load) instead of at the end (image_imagemagick_save). That way, a custom effect can either change the current setting or just add another op (preferred imo) to override the default setting.

Please note that the "quality" setting can equally well be used for PNG, so there should be no mention of or restriction to jpg.

Related imagecache_actions issue: #1113530: Changing jpg quality does not seem to work.

mondrake’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Drupal 7 is EOL