You are here

class JpegTran in Image Optimize Binaries 8

Uses the JpegTran binary to optimize images.

Plugin annotation


@ImageAPIOptimizeProcessor(
  id = "jpegtran",
  label = @Translation("JpegTran"),
  description = @Translation("Uses the JpegTran binary to optimize images.")
)

Hierarchy

  • class \Drupal\imageapi_optimize_binaries\ImageAPIOptimizeProcessorBinaryBase extends \Drupal\imageapi_optimize\ConfigurableImageAPIOptimizeProcessorBase
    • class \Drupal\imageapi_optimize_binaries\Plugin\ImageAPIOptimizeProcessor\JpegTran

Expanded class hierarchy of JpegTran

File

src/Plugin/ImageAPIOptimizeProcessor/JpegTran.php, line 17

Namespace

Drupal\imageapi_optimize_binaries\Plugin\ImageAPIOptimizeProcessor
View source
class JpegTran extends ImageAPIOptimizeProcessorBinaryBase {

  /**
   * {@inheritdoc}
   */
  protected function executableName() {
    return 'jpegtran';
  }
  public function applyToImage($image_uri) {
    if ($cmd = $this
      ->getFullPathToBinary()) {
      $dst = $this
        ->sanitizeFilename($image_uri);
      if ($this
        ->getMimeType($image_uri) == 'image/jpeg') {
        $options = array(
          '-copy none',
          '-optimize',
        );
        $arguments = array(
          $dst,
        );
        if ($this->configuration['progressive']) {
          $options[] = '-progressive';
        }
        $option_string = implode(' ', $options);
        $argument_string = implode(' ', array_map('escapeshellarg', $arguments));
        return $this
          ->saveCommandStdoutToFile(escapeshellarg($cmd) . ' ' . $option_string . ' ' . $argument_string, $dst);
      }
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'progressive' => FALSE,
    ];
  }
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['progressive'] = array(
      '#title' => $this
        ->t('Progressive'),
      '#type' => 'checkbox',
      '#default_value' => $this->configuration['progressive'],
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    $this->configuration['progressive'] = $form_state
      ->getValue('progressive');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImageAPIOptimizeProcessorBinaryBase::$fileSystem protected property The file system service.
ImageAPIOptimizeProcessorBinaryBase::$shellOperations protected property The imageapi shell operation service.
ImageAPIOptimizeProcessorBinaryBase::create public static function
ImageAPIOptimizeProcessorBinaryBase::execShellCommand protected function Execute a shell command on the local system.
ImageAPIOptimizeProcessorBinaryBase::findExecutablePath protected function Search the local system for the given executable binary.
ImageAPIOptimizeProcessorBinaryBase::getFullPathToBinary public function
ImageAPIOptimizeProcessorBinaryBase::getSummary public function
ImageAPIOptimizeProcessorBinaryBase::sanitizeFilename protected function Sanitize the given path for binary processors.
ImageAPIOptimizeProcessorBinaryBase::saveCommandStdoutToFile protected function
ImageAPIOptimizeProcessorBinaryBase::__construct public function
JpegTran::applyToImage public function Overrides ImageAPIOptimizeProcessorBinaryBase::applyToImage
JpegTran::buildConfigurationForm public function Overrides ImageAPIOptimizeProcessorBinaryBase::buildConfigurationForm
JpegTran::defaultConfiguration public function Overrides ImageAPIOptimizeProcessorBinaryBase::defaultConfiguration
JpegTran::executableName protected function Overrides ImageAPIOptimizeProcessorBinaryBase::executableName
JpegTran::submitConfigurationForm public function Overrides ImageAPIOptimizeProcessorBinaryBase::submitConfigurationForm