Hello, I had issue for optimize png with pngquant. After some recherche, I have find that if I simplify the "exec" command inside the function "imageapi_optimize_binaries_pngquant", the optimization works better...
So, that patch is for everybody who get some no optimized image with pngquant.

Info : pngquant 2.0.1 on Ubuntu 12.04 LTS installed with :
sudo add-apt-repository ppa:danmbox/ppa
sudo apt-get update
sudo apt-get install pngquant

Comments

steveoriol’s picture

garphy’s picture

Your patch simply allows pngquant to compress more by setting no limit on the quality.

What would be great is to be able to set up the --quality setting within the UI as provided by some other integrated tools.

joelpittet’s picture

+1 to @garphy's comment #2. Would be nice to have this configurable.

christophweber’s picture

Category: Bug report » Feature request
Status: Needs review » Needs work

Agree with @garphy and @joelpittet. This patch is making assumptions which should be under end user control, hopefully with some help to make them understand the consequences.

attisan’s picture

Status: Needs work » Needs review
StatusFileSize
new4.14 KB

I'm not yet done - but in case anyone needs settings for pngquant + (what is more) an option to 'force rewrite' images with wrong extentions (as is the case when jpgs are converted to pngs).

I will try to finish my work within the next weeks.

hth

nikolay shapovalov’s picture

Status: Needs review » Needs work

1) Can't apply patch, use path from root of the module.
2) trailing whitespace (line 97 of patch)

+++ b/sites/all/modules/contrib_fields/imageapi_optimize/binaries/pngquant.inc
@@ -12,15 +12,94 @@ function imageapi_optimize_binaries_pngquant_info() {
+      $extension = $settings['ext'];
+    }
+    ¶
+    $command = $cmd .
+      ' --speed=' . $settings['speed'].
attisan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.75 KB

oooh gosh :-( - I'm sorry.

jethro’s picture

Thanks
I needed to change the quality for pngquant to get better compression as well and this was useful.
One change I might make is splitting the quality settings into two separate integer fields for a min and a max as the current textfield seems like something that someone could enter bad data and/or forget the correct format easily. An example in the description might be enough.

steven jones’s picture

Title: pngquant optimize » Add options for pngquant optimize
Version: 7.x-1.2 » 8.x-2.x-dev
Status: Needs review » Needs work

Moving to the latest module version queue.

Lets tidy this patch up and get it in.

mschudders’s picture

Status: Needs work » Needs review
StatusFileSize
new3.67 KB

Drupal 8 patch attached.

svdhout’s picture

I can confirm that the patch in #10 works on 8.5.x

steven jones’s picture

Project: Image Optimize » Image Optimize Binaries
Version: 8.x-2.x-dev »
tim-diels’s picture

Version: » 8.x-1.0-alpha1
StatusFileSize
new3.69 KB

After splitting the modules in separate modules, the patch does not apply anymore. Rerolled the patch against correct module.

borisson_’s picture

Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
Status: Needs review » Needs work

There are a couple of coding standards issues in the latest patch, the indentation is incorrect.

+++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
@@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
+    $form['speed'] = [
+        '#title' => $this->t('Speed'),
+        '#type' => 'select',
+        '#options' => array_combine(range(1, 10), range(1, 10)),
+        '#default_value' => $this->configuration['speed'],
+        '#description' => $this->t('1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is about 8 times faster than the default.'),
+      ];
...
+    $form['quality'] = [
+        '#title' => $this->t('Quality'),
...
+    $form['ext'] = [
+        '#title' => $this->t('File extension'),
tim-diels’s picture

StatusFileSize
new3.65 KB

Re-rolled because of CS.

tim-diels’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, let's get this in!

steven jones’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the patches and reviews all!

I think there's still some things we could do here before we get this in. Nothing too major I don't think.

  1. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    -          '--ext .png'
    ...
    +          $options[] = '--ext ' . escapeshellarg($this->configuration['ext']);
    

    From what I understand we are aiming to optimise the image 'in place'. So we really do want to overwrite the existing file passed into the processor.

    Allowing the file extension that pngquant is going to output might mean that a misconfiguration would stop the optimization processing from working correctly.

    What's the reasoning for allowing this option to be customised?

  2. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    +      '#options' => array_combine(range(1, 10), range(1, 10)),
    

    I think we need to specify '#empty_value' => '' otherwise once you've selected a value, there's no way to go back to not specifying one. Or we should change the default value to 3 to match pngquant.

    Also, https://www.mankier.com/1/pngquant#Synopsis suggests that the max should be 11?

  3. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    +      '#description' => $this->t('1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is about 8 times faster than the default.'),
    

    Our default is 1, not 3. Can we provide some better help text here or a change a default somewhere please?

  4. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    +      '#type' => 'textfield',
    

    I think we should split this into two 'number' elements please. This will give us some validation too, if we correctly specify '#min' and '#max'.

    A range slider with two handles might be better, but harder to make work cross-browser I think.

  5. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    +If conversion results in quality below the min quality the image won‘t be saved<br/>
    +(or if outputting to stdin, 24-bit original will be output) and pngquant will<br/>
    +exit with status code 99.'),
    

    Is this bit of the comment required? Do I need to worry about exit codes when picking a number here?

    Should this say something along the lines of: if pngquant can't produce a good enough quality image then the original image will be left unchanged?

  6. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    +      '#title' => $this->t('File extension'),
    

    I don't think it makes sense to allow this to be customised, so I think we can removed this form element.

  7. +++ b/src/Plugin/ImageAPIOptimizeProcessor/PngQuant.php
    @@ -25,21 +26,84 @@ class PngQuant extends ImageAPIOptimizeProcessorBinaryBase {
    +  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    

    I think we need to add some validation to the form, especially for the quality element. If we switch to using two number elements then we should only need to verify that min < max.

steven jones’s picture

Component: Code » PngQuant Processor

  • Steven Jones committed c5ea586 on 8.x-1.x
    Issue #2452111 by tim-diels, attisan, steveoriol, Mschudders, borisson_...
  • Steven Jones committed d56fe2c on 8.x-1.x
    Issue #2452111 by Steven Jones: Add options for pngquant optimize
    
steven jones’s picture

Status: Needs work » Fixed

Thanks for the patches, reviews and patience everyone! This is now in 8.x-1.x.

steven jones’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

gaurav_manerkar’s picture

StatusFileSize
new1.71 KB

I have created a patch with file extension option for pngQuant
This patch is for 8.x-1.0-alpha2 version of module.