Exemple #1
0
 public function processOperations(Image $input_image, Image $output_image = null)
 {
     $command_line = $this->getImageMagickConvert();
     $this->temp_input_filename = $this->getTempFilename('input_');
     file_put_contents($this->temp_input_filename, $input_image->getImageData());
     // Check for a SequenceNumber or Density operation.  They're a little special.
     foreach ($this->operations as $index => $operation) {
         if ($operation instanceof SequenceNumber) {
             $frame = (int) $operation->getValue();
             if (!$frame) {
                 throw new ImageMagickException('Frame was not an integer');
             }
             $this->temp_input_filename .= '[' . $frame . ']';
             unset($this->operations[$index]);
         }
         if ($operation instanceof Density) {
             $density = (int) $operation->getValue();
             if (!$density) {
                 throw new ImageMagickException('Density was not an integer');
             }
             $command_line .= ' -density ' . $density;
             unset($this->operations[$index]);
         }
     }
     $command_line .= ' ' . escapeshellarg($this->temp_input_filename) . ' ';
     foreach ($this->operations as $operation) {
         if ($operation instanceof InstantOperation) {
             return $operation->process($input_image, $command_line);
         }
         $command_line = $operation->process($input_image, $command_line)->getCommandLine() . ' ';
     }
     $temp_output_filename = '';
     if ($output_image) {
         $temp_output_filename = $this->getTempFilename('output_');
         $command_line .= $this->getOutputFileWithFormat($temp_output_filename);
     }
     // Remove extra whitespace between operations
     $command_line = preg_replace('/\\s+/', ' ', $command_line);
     // Check for a no-op.  Don't lose fidelity by converting it to itself
     // Also check to make sure it hasn't been forced.  We assume that the Convert operation wouldn't set the format if it didn't have to.
     if (!$this->output_format_is_forced && trim($command_line) == $this->getImageMagickConvert() . ' ' . escapeshellarg($this->temp_input_filename) . ' ' . $this->getOutputFileWithFormat($temp_output_filename)) {
         copy($this->temp_input_filename, $temp_output_filename);
         $output = array('No-op; Copied image');
         $status = 0;
     } else {
         exec($command_line, $output, $status);
     }
     if ($status) {
         throw new ImageMagickException('Error executing ImageMagick: ' . $status);
     }
     if ($output_image && $this->temp_input_filename) {
         $output_image->setImageData(file_get_contents($temp_output_filename));
     }
     return implode("\n", $output);
 }