Ejemplo n.º 1
0
 public function process(Image $image, $command_line = '')
 {
     if (!$this->watermark_image) {
         throw new ImageMagickException('Can\'t watermark if there\'s no image to watermark with!');
     }
     $pre_watermark_filename = $this->processor->getTempFilename('pre_watermark_');
     $watermark_filename = $this->processor->getTempFilename('watermark_');
     // Run the current queue to see how big the resultant image is.
     exec($command_line . ' ' . escapeshellarg($pre_watermark_filename));
     file_put_contents($watermark_filename, $this->watermark_image->getImageData());
     // 0 => width, 1 => height
     $image_data = getimagesize($pre_watermark_filename);
     // Fit the watermark to 0.98 * the size of the image, assuming the image is big enough.
     $scale = 0.98;
     $maxsize = min($image_data[0], $image_data[1]);
     $width = intval($maxsize * $scale);
     // Only watermark if it's bigger than a certain size.
     if ($image_data[0] >= self::MAX_WATERMARK_WIDTH || $image_data[1] >= self::MAX_WATERMARK_HEIGHT) {
         if ($this->processor->isWindows()) {
             $command_line .= ' -gravity center ( ' . escapeshellarg($watermark_filename) . ' -resize ' . $width . 'x' . $width . ' ) -composite ';
         } else {
             $command_line .= ' -gravity center \\( ' . escapeshellarg($watermark_filename) . ' -resize ' . $width . 'x' . $width . ' \\) -composite ';
         }
     }
     $result = new Result();
     $result->setCommandLine($command_line);
     return $result;
 }
Ejemplo n.º 2
0
 public function process(Image $image, $command_line = '')
 {
     if (!$this->format) {
         throw new ImageMagickException('Can\'t change format to nothing!!');
     }
     // Sneaky!  Eat my own dog food to get in the image information.
     $processor = clone $this->processor;
     $processor->addOperation(new Info());
     $info = $processor->processOperations($image)->getExtra();
     $from = 'unknown';
     switch ($info['type']) {
         case 'JPEG':
             $from = CommonOptions::FORMAT_JPG;
             break;
         case 'GIF':
             $from = CommonOptions::FORMAT_GIF;
             break;
         case 'PNG':
             $from = CommonOptions::FORMAT_PNG;
             break;
     }
     if ($from != $this->format) {
         $this->processor->setOutputFormat($this->format);
     }
     $result = new Result();
     $result->setCommandLine($command_line);
     return $result;
 }
Ejemplo n.º 3
0
 public function process(Image $image, $command_line = '')
 {
     if (!$this->width || !$this->height) {
         throw new ImageMagickException('Need both width and height to slice an image');
     }
     $command_line .= ' -background white -gravity ' . escapeshellarg($this->gravity) . ' -extent ' . escapeshellarg($this->width . 'x' . $this->height . '+' . $this->offset_x . '+' . $this->offset_y);
     $result = new Result();
     $result->setCommandLine($command_line);
     return $result;
 }
Ejemplo n.º 4
0
 public function process(Image $image, $command_line = '')
 {
     $status = 0;
     $output = array();
     $temp_file = $this->processor->getTempFilename('info_');
     file_put_contents($temp_file, $image->getImageData());
     exec($this->processor->getImageMagickConvert() . ' -density 120 ' . escapeshellarg($temp_file) . ' -format "%w,%h,%z,%m,%Q" info:', $output, $status);
     $result = new Result();
     $result->setCommandLine($command_line);
     if (!$status) {
         $size_arr = explode(',', $output[0]);
         $result->setExtra(array('width' => $size_arr[0], 'height' => $size_arr[1], 'depth' => $size_arr[2], 'type' => $size_arr[3], 'quality' => $size_arr[4]));
     }
     return $result;
 }
Ejemplo n.º 5
0
 public function process(Image $image, $command_line = '')
 {
     if ($this->mode & CommonOptions::MODE_FILL_AREA_OR_FIT) {
         // Both...so if it's larger, shrink it to fill the area.
         // Otherwise, fit it.
         // What's my current width & height?
         $current_image_filename = $this->processor->getTempFilename('current_');
         $output_filename = $this->processor->getTempFilename('resize_temp_');
         file_put_contents($current_image_filename, $image->getImageData());
         // 0 => width, 1 => height
         $current_image_data = getimagesize($current_image_filename);
         exec($command_line . ' ' . escapeshellarg($output_filename));
         // 0 => width, 1 => height
         $image_data = getimagesize($output_filename);
         // Image is smaller in some dimension.  Follow the "Only shrink larger" directive, just fit instead.
         if ($image_data[0] < $current_image_data[0] || $image_data[1] < $current_image_data[1]) {
             $this->mode = 0;
         } elseif ($this->width == $image_data[0] && $this->height == $image_data[1]) {
             // The image is the exact same size.  Don't lose fidelity by resizing it.
             $result = new Result();
             $result->setCommandLine($command_line);
             return $result;
         } else {
             $this->mode = CommonOptions::MODE_FILL_AREA;
         }
     }
     if ($this->mode & CommonOptions::MODE_ONLY_SHRINK_LARGER) {
         $command_line .= ' -gravity ' . escapeshellarg($this->gravity);
         $command_line .= ' -thumbnail ' . escapeshellarg($this->width . 'x' . $this->height . '>');
     } elseif ($this->mode & CommonOptions::MODE_FILL_AREA) {
         $command_line .= ' -gravity ' . escapeshellarg($this->gravity);
         $command_line .= ' -thumbnail ' . escapeshellarg($this->width . 'x' . $this->height . '^');
     } elseif ($this->mode & CommonOptions::MODE_RESIZE_ABSOLUTE) {
         $command_line .= ' -gravity ' . escapeshellarg($this->gravity);
         $command_line .= ' -thumbnail ' . escapeshellarg($this->width . 'x' . $this->height . '!');
     } else {
         $command_line .= ' -gravity ' . escapeshellarg($this->gravity);
         $command_line .= ' -thumbnail ' . escapeshellarg($this->width . 'x' . $this->height);
     }
     $result = new Result();
     $result->setCommandLine($command_line);
     return $result;
 }
Ejemplo n.º 6
0
 public function process(Image $image, $command_line = '')
 {
     if (!$this->compare_to) {
         throw new ImageMagickException('No image to compare to!');
     }
     $output_file = $this->processor->getTempFilename('output_');
     $left_file = $this->processor->getTempFilename('left_');
     $right_file = $this->processor->getTempFilename('right_');
     if ($this->use_current) {
         $status = 0;
         $output = array();
         // Use the current queue, not the given file.
         exec($command_line . ' ' . $left_file, $output, $status);
         if ($status) {
             throw new ImageMagickException('Could not compare images: ' . implode("\n", $output));
         }
     } else {
         file_put_contents($left_file, $image->getImageData());
     }
     file_put_contents($right_file, $this->compare_to->getImageData());
     $status = 0;
     $output = array();
     exec($this->processor->getImageMagickPath() . DIRECTORY_SEPARATOR . 'compare -metric PSNR ' . escapeshellarg($left_file) . ' ' . escapeshellarg($right_file) . ' ' . ' -quality 100 ' . escapeshellarg($output_file) . ' 2>&1', $output, $status);
     if ($status == 1 && $this->processor->hasImageMagickQuirk(Processor::QUIRK_RESULT_IS_ONE_WHEN_COMPARE_FAILS)) {
         // $status > 1 means something else failed.  1 means the images weren't exactly the same.
         $status = 0;
     }
     if ($status == 0) {
         if (stripos($output[0], 'inf') !== false) {
             // IM sometimes returns 1.#INF instead of "inf".  Normalize it to what we expect.
             $output[0] = 'inf';
         }
     }
     if ($status) {
         throw new ImageMagickException('Could not compare images: (' . $status . ') ' . implode("\n", $output));
     }
     $result = new Result();
     $result->setCommandLine($command_line);
     if (!$status) {
         $result->setImage(new File($output_file))->setExtra(implode(PHP_EOL, $output));
     }
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * @param Image  $image
  * @param string $command_line
  *
  * @return Result
  */
 public function process(Image $image, $command_line = '')
 {
     $result = new Result();
     $result->setCommandLine($command_line . ' -profile ' . escapeshellarg($this->profile));
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * @param Image  $image
  * @param string $command_line
  *
  * @return Result
  */
 public function process(Image $image, $command_line = '')
 {
     $result = new Result();
     $result->setCommandLine($command_line . ' -strip');
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * @param Image $image
  * @param string $command_line
  *
  * @return Result
  */
 public function process(Image $image, $command_line = '')
 {
     $result = new Result();
     $result->setCommandLine($command_line . ' -blur ' . escapeshellarg($this->radius . 'x' . $this->sigma));
     return $result;
 }