Loading image_optimize_effect.module +28 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ function image_optimize_effect_image_effect_info() { 'label' => t('pngquant'), 'help' => t('Uses pngquant, see https://github.com/pornel/improved-pngquant or http://pngquant.org/'), 'effect callback' => 'image_optimize_effect_pngquant', 'form callback' => 'image_optimize_effect_pngquant_form', 'dimensions passthrough' => TRUE, ), 'image_optimize_effect_imgmin' => array( Loading @@ -36,10 +37,16 @@ function image_optimize_effect_image_effect_info() { * TRUE on success. FALSE on failure. * */ function image_optimize_effect_pngquant($image) { $extension = str_replace('jpg', 'jpeg', $image->info['extension']);; function image_optimize_effect_pngquant($image, $data) { // Merge defaults $data += array( 'speed' => 10, ); $extension = str_replace('jpg', 'jpeg', $image->info['extension']); // Only works on png files. if ($extension == 'png') { if ($extension != 'png') { return TRUE; } Loading @@ -60,7 +67,7 @@ function image_optimize_effect_pngquant($image) { $drupal_path = DRUPAL_ROOT; $pngquant_path = ''; $convert_path = 'pngquant'; $command_args = '--speed 10 --ext .png -f -v ' . $destination; $command_args = '--speed ' . $data['speed'] . ' --ext .png -f -v ' . $destination; if (strstr($_SERVER['SERVER_SOFTWARE'], 'Win32') || strstr($_SERVER['SERVER_SOFTWARE'], 'IIS')) { // Use Window's start command with the /B flag to make the process run in Loading Loading @@ -126,6 +133,23 @@ function image_optimize_effect_pngquant($image) { return FALSE; } /** * Form structure for pngquant. * * @param $data * The current configuration for this effect. */ function image_optimize_effect_pngquant_form($data) { $form['speed'] = array( '#type' => 'select', '#options' => drupal_map_assoc(range(1, 10)), '#title' => t('Speed'), '#description' => t('Speed/quality trade-off from 1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default.'), '#default_value' => isset($data['speed']) ? $data['speed'] : 10, ); return $form; } /** * Image effect callback; Optimize using imgmin. * Loading Loading
image_optimize_effect.module +28 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ function image_optimize_effect_image_effect_info() { 'label' => t('pngquant'), 'help' => t('Uses pngquant, see https://github.com/pornel/improved-pngquant or http://pngquant.org/'), 'effect callback' => 'image_optimize_effect_pngquant', 'form callback' => 'image_optimize_effect_pngquant_form', 'dimensions passthrough' => TRUE, ), 'image_optimize_effect_imgmin' => array( Loading @@ -36,10 +37,16 @@ function image_optimize_effect_image_effect_info() { * TRUE on success. FALSE on failure. * */ function image_optimize_effect_pngquant($image) { $extension = str_replace('jpg', 'jpeg', $image->info['extension']);; function image_optimize_effect_pngquant($image, $data) { // Merge defaults $data += array( 'speed' => 10, ); $extension = str_replace('jpg', 'jpeg', $image->info['extension']); // Only works on png files. if ($extension == 'png') { if ($extension != 'png') { return TRUE; } Loading @@ -60,7 +67,7 @@ function image_optimize_effect_pngquant($image) { $drupal_path = DRUPAL_ROOT; $pngquant_path = ''; $convert_path = 'pngquant'; $command_args = '--speed 10 --ext .png -f -v ' . $destination; $command_args = '--speed ' . $data['speed'] . ' --ext .png -f -v ' . $destination; if (strstr($_SERVER['SERVER_SOFTWARE'], 'Win32') || strstr($_SERVER['SERVER_SOFTWARE'], 'IIS')) { // Use Window's start command with the /B flag to make the process run in Loading Loading @@ -126,6 +133,23 @@ function image_optimize_effect_pngquant($image) { return FALSE; } /** * Form structure for pngquant. * * @param $data * The current configuration for this effect. */ function image_optimize_effect_pngquant_form($data) { $form['speed'] = array( '#type' => 'select', '#options' => drupal_map_assoc(range(1, 10)), '#title' => t('Speed'), '#description' => t('Speed/quality trade-off from 1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default.'), '#default_value' => isset($data['speed']) ? $data['speed'] : 10, ); return $form; } /** * Image effect callback; Optimize using imgmin. * Loading