protected function executeExecImagick()
 {
     $op = '-resize ';
     if (!empty($this->algorithm)) {
         $op .= " -filter {$this->algorithm} ";
     }
     if ($this->scalePercent > 0) {
         $op .= "\"{$this->scalePercent}%\"";
     } else {
         if ($this->height > 0 && $this->width > 0) {
             $op .= "{$this->width}x{$this->height}";
             if (!$this->constrainProportions) {
                 $op .= '!';
             }
         } else {
             if ($this->width > 0) {
                 $op .= "{$this->width}";
             } else {
                 $op .= "x{$this->height}";
             }
         }
     }
     if (!empty($this->unsharp)) {
         $op .= " -unsharp {$this->unsharp}";
     }
     return ImagickExecFilterHelper::executeFilter($this, $op);
 }
 protected function executeExecImagick()
 {
     if ($this->mode == 'distort') {
         if ($this->scale > 0) {
             $op = "-distort SRT \"{$this->scale},{$this->degrees}\"";
         } else {
             $op = "-distort SRT \"{$this->degrees}\"";
         }
     } else {
         if ($this->autoCrop) {
             // if degrees is a multiple of 90, just do regular rotate
             $x = $this->degrees % 90;
             if ($x == 0) {
                 $op = "-rotate \"{$this->degrees}\"";
             } else {
                 // use 1.3 as default scale
                 $scale = $this->scale > 0 ? $this->scale : 1.3;
                 $op = "-distort SRT \"{$scale},{$this->degrees}\"";
             }
         } else {
             $op = "-background \"{$this->backgroundColor}\" -rotate \"{$this->degrees}\"";
         }
     }
     return ImagickExecFilterHelper::executeFilter($this, $op);
 }
 protected function executeExecImagick()
 {
     $op = '';
     if (!empty($this->anchor)) {
         $op .= "-gravity {$this->anchor} ";
     }
     $op .= "-crop {$this->width}x{$this->height}{$this->offsetX}{$this->offsetY}";
     return ImagickExecFilterHelper::executeFilter($this, $op);
 }
 protected function executeExecImagick()
 {
     $op = '';
     $op .= "-gravity {$this->anchor} ";
     $op .= "-crop {$this->cropWidth}x{$this->cropHeight}{$this->offsetX}{$this->offsetY}! ";
     $op .= "-background white -flatten ";
     $op .= "-resize {$this->width}x{$this->height}";
     return ImagickExecFilterHelper::executeFilter($this, $op);
 }
 protected function executeExecImagick()
 {
     $op = "-size {$this->width}x{$this->height}";
     if (!empty($this->image)) {
         if ($this->repeat) {
             $op .= " tile:\"{$this->image}\"";
         } else {
             $op .= " -gravity NorthWest";
             $op .= " xc:\"{$this->color}\"";
             $op .= " -draw 'image over 0,0 0,0 \"{$this->image}\"'";
         }
     } else {
         $op .= " xc:\"{$this->color}\"";
     }
     $op .= " -gravity {$this->anchor}";
     $op .= " -draw 'image srcover ";
     $this->offsetX = -1 * intval($this->offsetX);
     $this->offsetY = -1 * intval($this->offsetY);
     $op .= " {$this->offsetX},{$this->offsetY}";
     $op .= ' 0,0';
     $op .= " \"{$this->sourceFile}\"'";
     return ImagickExecFilterHelper::executeFilter($this, $op, true);
 }
 protected function executeExecImagick()
 {
     // Step 1. Generate the watermark
     $op = '';
     // store original values
     $fileType = $this->outputType;
     $targetFile = $this->targetFile;
     $this->outputAlpha = true;
     if ($this->type == 'text') {
         $this->outputType = 'png';
         $this->targetFile = FileSystemUtils::secureTmpname($this->workDir, 'watermark', '.' . $this->outputType);
         $op .= " -background transparent";
         $op .= " -fill '{$this->fontColor}'";
         if (!empty($this->fontFamily)) {
             $op .= " -font '{$this->fontFamily}'";
         }
         if (!empty($this->fontStyle)) {
             $op .= " -style '{$this->fontStyle}'";
         }
         if (!empty($this->fontWeight)) {
             $op .= " -weight '{$this->fontWeight}'";
         }
         $op .= " -size {$this->width}x{$this->height}";
         if (!empty($this->fontSize)) {
             $op .= " -pointsize {$this->fontSize}";
         }
         $op .= " caption:\"" . preg_replace('/"/', '\\"', $this->text) . "\"";
         $watermark = ImagickExecFilterHelper::executeFilter($this, $op, true);
     } else {
         if ($this->type == 'image') {
             $watermark = $this->image;
         }
     }
     // Step 2. Apply the watermark
     // restore original values
     $this->outputType = $fileType;
     $this->targetFile = $targetFile;
     /** This only works with IM > 6.5.3-4 **/
     /*$op = "\"{$watermark}\"";
     
             $op .= " -compose dissolve";
     
             $op .= " -define compose:args={$this->opacity}";
     
             $op .= " -gravity {$this->anchor}";
     
             $op .= " -geometry {$this->offsetX}{$this->offsetY}";
     
             $op .= " -composite";
     
             $image = ImagickExecFilterHelper::executeFilter($this, $op);*/
     $inFile = escapeshellarg($this->sourceFile);
     $outFile = escapeshellarg($this->targetFile);
     $op = " -dissolve {$this->opacity}";
     $op .= " -gravity {$this->anchor}";
     $op .= " -geometry {$this->offsetX}{$this->offsetY}";
     $op .= " \"{$watermark}\"";
     $op .= " {$inFile}";
     if ($this->outputAlpha != null) {
         if ($this->outputAlpha == true) {
             $op .= " -alpha On";
         } else {
             $op .= " -alpha Off";
         }
     }
     $op .= " -quality {$this->outputQuality}";
     $cmdParams = "{$op} {$outFile}";
     $cmd = "{$this->imageCompositeExecPath} {$cmdParams} 2>&1";
     $retval = 1;
     $output = array();
     exec($cmd, $output, $retval);
     if ($retval > 0) {
         throw new ImageFilterException("Image filter process failed", $output);
     }
     @unlink($watermark);
     return $this->targetFile;
 }
 protected function executeExecImagick()
 {
     // get the width of the original image
     $retval = 1;
     $output = array();
     exec("{$this->imageIdentifyExecPath} -format %w " . escapeshellarg($this->sourceFile) . " 2>&1", $output, $retval);
     if ($retval > 0) {
         throw new ImageFilterException("Unable to read source file.");
     }
     $width = $output[0] - $this->padding * 2;
     // Step 1. Generate the photo credit
     $op = '';
     // store original values
     $targetFile = $this->targetFile;
     $this->targetFile = FileSystemUtils::secureTmpname($this->workDir, 'credit', '.' . $this->outputType);
     $op .= " -background '{$this->backgroundColor}'";
     if ($this->fontColor != null) {
         $op .= " -fill '{$this->fontColor}'";
     }
     if ($this->fontFamily != null) {
         $op .= " -font '{$this->fontFamily}'";
     }
     if ($this->fontStyle != null) {
         $op .= " -style '{$this->fontStyle}'";
     }
     if ($this->fontWeight != null) {
         $op .= " -weight '{$this->fontWeight}'";
     }
     $op .= " -pointsize {$this->fontSize}";
     // Force height to fontSize because IM < version 6.5.2-4 will ignore -pointsize to make the text fill the maximum width specified
     // I think this will limit all credit to 1 line of text
     $op .= " -size {$width}x{$this->fontSize}";
     $op .= " -gravity {$this->anchor}";
     $op .= " label:\"" . preg_replace('/"/', '\\"', $this->text) . "\"";
     $op .= " -bordercolor '{$this->backgroundColor}'";
     $op .= " -border {$this->padding}x{$this->padding}";
     $credit = ImagickExecFilterHelper::executeFilter($this, $op, true);
     // Step 2. Apply the photo credit
     // restore original values
     $this->targetFile = $targetFile;
     $op = '';
     if ($this->type == 'overlay') {
         $op .= " -gravity {$this->anchor}";
         $op .= " -draw 'image over 0,0 0,0 \"{$credit}\"'";
     } else {
         if ($this->type == 'add') {
             $op .= " -background '{$this->backgroundColor}'";
             $op .= " {$credit}";
             if (preg_match('/^North/i', $this->anchor)) {
                 $op .= " +swap";
             }
             if (preg_match('/^(North|South)$/i', $this->anchor)) {
                 $op .= " -gravity Center";
             } else {
                 if (preg_match('/East$/i', $this->anchor)) {
                     $op .= " -gravity East";
                 }
             }
             $op .= " -append";
         }
     }
     return ImagickExecFilterHelper::executeFilter($this, $op);
 }
 protected function executeExecImagick()
 {
     $op = '';
     $op .= "-crop {$this->width}x{$this->height}{$this->offsetX}{$this->offsetY}";
     return ImagickExecFilterHelper::executeFilter($this, $op);
 }