/**
  * Rotates an image to $deg degree
  * @param integer $deg: The amount to rotate
  * @param string $bgcolor: The background color in html hexadecimal notation
  * @return sfFilebasePluginImage $image: THe rotated image
  */
 public function rotate($deg, $bgcolor)
 {
     $ret_val = $this->destination_resource->rotateImage(new ImagickPixel($bgcolor), $deg);
     if ($ret_val !== true) {
         throw new sfFilebasePluginException(sprintf('Failed to rotate image %s.', $this->source));
     }
     return $ret_val;
 }
예제 #2
0
 protected function _rotate($degrees)
 {
     if ($this->im->rotateImage(new ImagickPixel(), $degrees)) {
         $this->width = $this->im->getImageWidth();
         $this->height = $this->im->getImageHeight();
         return true;
     }
     return false;
 }
function gradientRight($width, $height)
{
    $imagick = new Imagick();
    $imagick->newPseudoImage($width, $height, 'gradient:white-black');
    $imagick->rotateImage('none', 90);
    return $imagick;
}
예제 #4
0
 /**
  * @param  $angle
  * @param bool $autoResize
  * @param string $color
  * @return Pimcore_Image_Adapter_Imagick
  */
 public function rotate($angle)
 {
     $this->resource->rotateImage(new ImagickPixel('none'), $angle);
     $this->setWidth($this->resource->getimagewidth());
     $this->setHeight($this->resource->getimageheight());
     $this->reinitializeImage();
     return $this;
 }
예제 #5
0
 /**
  * Rotate the image.
  * @param int $degrees
  */
 protected function _rotate($degrees)
 {
     if ($this->im->rotateImage(new \ImagickPixel('transparent'), $degrees)) {
         $this->width = $this->im->getImageWidth();
         $this->height = $this->im->getImageHeight();
         $this->im->setImagePage($this->width, $this->height, 0, 0);
     }
 }
예제 #6
0
파일: Imagick.php 프로젝트: manaphp/manaphp
 /**
  * Rotate the image by a given degrees
  *
  * @param int   $degrees
  * @param int   $background
  * @param float $alpha
  *
  * @return static
  */
 public function rotate($degrees, $background = 0xffffff, $alpha = 1.0)
 {
     $backgroundColor = sprintf('rgba(%u,%u,%u,%f)', $background >> 16 & 0xff, $background >> 8 & 0xff, $background & 0xff, $alpha);
     $this->_image->rotateImage(new \ImagickPixel($backgroundColor), $degrees);
     $this->_image->setImagePage($this->_width, $this->_height, 0, 0);
     $this->_width = $this->_image->getImageWidth();
     $this->_height = $this->_image->getImageHeight();
     return $this;
 }
예제 #7
0
 public static function rotate(Imagick $image, $params)
 {
     if (isset($params[0])) {
         $angle = $params[0];
         if ($angle > 0 && $angle < 360) {
             $image->rotateImage(new ImagickPixel('none'), $angle);
         }
     }
 }
예제 #8
0
 /**
  * Rotate the current image.
  *
  * @param integer $angle       The angle to rotate the image by,
  *                             in the clockwise direction.
  * @param integer $background  The background color to fill any triangles.
  */
 public function rotate($angle, $background = 'white')
 {
     try {
         $this->_imagick->rotateImage($background, $angle);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $this->clearGeometry();
 }
예제 #9
0
 public function rotate($angle)
 {
     // Rotate
     try {
         $return = $this->_resource->rotateImage(new ImagickPixel('none'), $angle);
     } catch (ImagickException $e) {
         throw new Engine_Image_Adapter_Exception(sprintf('Unable to rotate image: %s', $e->getMessage()), $e->getCode());
     }
     return $this;
 }
예제 #10
0
 public function rotate($degree, $color = 'FFFFFF')
 {
     $rgb = $this->html2rgb($color);
     for ($r = 0; $r < count($this->image); $r++) {
         $this->image->nextImage();
         $this->image->rotateImage(new ImagickPixel('rgba(' . $rgb[0] . ',' . $rgb[1] . ',' . $rgb[2] . ',0)'), $degree);
     }
     $this->info['width'] = $this->image->getImageWidth();
     $this->info['height'] = $this->image->getImageHeight();
 }
예제 #11
0
 /**
  * @param $angle
  * @return $this
  */
 public function rotate($angle)
 {
     $this->preModify();
     $this->resource->rotateImage(new \ImagickPixel('none'), $angle);
     $this->setWidth($this->resource->getimagewidth());
     $this->setHeight($this->resource->getimageheight());
     $this->postModify();
     $this->setIsAlphaPossible(true);
     return $this;
 }
예제 #12
0
 public function rotate($newFile, $angle)
 {
     $imagick = new Imagick();
     $imagick->readImage($this->_file);
     $imagick->rotateImage(new ImagickPixel('#ffffff'), $angle);
     //$imagick->rotateImage(new ImagickPixel('transparent'), $angle);
     $imagick->writeImage($newFile);
     $imagick->clear();
     $imagick->destroy();
 }
예제 #13
0
 public function process(\Imagick $image)
 {
     $info = getimagesize($this->_file);
     if ($info['mime'] != 'image/jpeg') {
         return $image;
     }
     if (!($exif_data = exif_read_data($this->_file))) {
         return $image;
     }
     if (isset($exif_data['Orientation'])) {
         $ort = $exif_data['Orientation'];
         if ($ort > 1) {
             switch ($ort) {
                 case 2:
                     $image->flopImage();
                     break;
                 case 3:
                     $image->rotateImage(new \ImagickPixel(), 180);
                     break;
                 case 4:
                     $image->flipImage();
                     break;
                 case 5:
                     $image->flopImage();
                     $image->rotateImage(new \ImagickPixel(), 270);
                     break;
                 case 6:
                     $image->rotateImage(new \ImagickPixel(), 90);
                     break;
                 case 7:
                     $image->flopImage();
                     $image->rotateImage(new \ImagickPixel(), 90);
                     break;
                 case 8:
                     $image->rotateImage(new \ImagickPixel(), 270);
                     break;
             }
         }
     }
     return $image;
 }
예제 #14
0
 /**
  * 入力された画像がExifであればエラーを記録し、JFIFに変換します。
  * @param \Imagick $imagick JFIFかExif。
  */
 protected function convertExifToJFIF(\Imagick $imagick)
 {
     if ($imagick->getImageProperties('exif:*')) {
         $this->logger->error(sprintf(_('「%s」はExif形式です。'), $this->filename));
         switch ($imagick->getImageOrientation()) {
             case \Imagick::ORIENTATION_TOPRIGHT:
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_BOTTOMRIGHT:
                 $imagick->rotateImage('none', 180);
                 break;
             case \Imagick::ORIENTATION_BOTTOMLEFT:
                 $imagick->rotateImage('none', 180);
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_LEFTTOP:
                 $imagick->rotateImage('none', 90);
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_RIGHTTOP:
                 $imagick->rotateImage('none', 90);
                 break;
             case \Imagick::ORIENTATION_RIGHTBOTTOM:
                 $imagick->rotateImage('none', 270);
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_LEFTBOTTOM:
                 $imagick->rotateImage('none', 270);
                 break;
         }
         $imagick->stripImage();
     }
 }
예제 #15
0
파일: Imagick.php 프로젝트: anp135/altocms
 public function rotate($angle, $bg_color = 0xffffff, $bg_opacity = 0)
 {
     if ($this->multiframe()) {
         foreach ($this->image as $frame) {
             $frame->rotateImage($this->get_color($bg_color, $bg_opacity), -$angle);
             $frame->setImagePage($this->image->width, $this->image->height, 0, 0);
         }
     } else {
         $this->image->rotateImage($this->get_color($bg_color, $bg_opacity), -$angle);
     }
     $this->update_size($this->image->getImageWidth(), $this->image->getImageHeight());
     return $this;
 }
 /**
  * Rotates current image counter-clockwise by $angle.
  *
  * @since 3.5.0
  * @access public
  *
  * @param float $angle
  * @return true|WP_Error
  */
 public function rotate($angle)
 {
     /**
      * $angle is 360-$angle because Imagick rotates clockwise
      * (GD rotates counter-clockwise)
      */
     try {
         $this->image->rotateImage(new ImagickPixel('none'), 360 - $angle);
         // Since this changes the dimensions of the image, update the size.
         $result = $this->update_size();
         if (is_wp_error($result)) {
             return $result;
         }
         $this->image->setImagePage($this->size['width'], $this->size['height'], 0, 0);
     } catch (Exception $e) {
         return new WP_Error('image_rotate_error', $e->getMessage());
     }
     return true;
 }
 /**
  * Rotates the current image
  *
  * @param float $angle Rotation angle in degree
  * @param array $options Supported options:
  * <ul>
  *  <li>'canvasColor' : array(r ,g, b), named color or #rrggbb</li>
  * </ul>
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function rotate($angle, $options = null)
 {
     if ($angle % 360 == 0) {
         return true;
     }
     $color = $this->_getColor('canvasColor', $options, array(255, 255, 255));
     if (is_array($color)) {
         $color = $this->colorarray2colorhex($color);
     }
     $pixel = new ImagickPixel($color);
     try {
         $this->imagick->rotateImage($pixel, $angle);
     } catch (ImagickException $e) {
         return $this->raiseError('Cannot create a new imagick image for the rotation: ' . $e->getMessage(), IMAGE_TRANSFORM_ERROR_FAILED);
     }
     $info = $this->imagick->getImageGeometry();
     $this->new_x = $info['width'];
     $this->new_y = $info['height'];
     return true;
 }
 private function rotate_imagick($imagePath, $orientation)
 {
     $imagick = new Imagick($imagePath);
     $imagick->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
     $deg = 0;
     switch ($orientation) {
         case 3:
             $deg = -180;
             break;
         case 6:
             $deg = 90;
             break;
         case 8:
             $deg = -90;
             break;
     }
     $imagick->rotateImage(new ImagickPixel('#00000000'), $deg);
     $imagick->writeImage($imagePath);
     $imagick->clear();
     $imagick->destroy();
 }
 function weldMaps2PNG_rotate($urls, $filename, $angle, $encode = true)
 {
     if (!$urls || $urls == "") {
         $e = new mb_exception("weldMaps2PNG_rotate: no maprequests delivered");
     }
     $url = explode("___", $urls);
     $obj1 = new stripRequest($url[0]);
     $width = $obj1->get("width");
     $height = $obj1->get("height");
     //calculate rotated dimensions
     $neededWidth = round(abs(sin(deg2rad($angle)) * $height) + abs(cos(deg2rad($angle)) * $width));
     $neededHeight = round(abs(sin(deg2rad($angle)) * $width) + abs(cos(deg2rad($angle)) * $height));
     //modify requests
     for ($i = 0; $i < count($url); $i++) {
         $obj = new stripRequest($url[$i]);
         $obj->set("width", $neededWidth);
         $obj->set("height", $neededHeight);
         $map_extent = $obj->get("BBOX");
         $coord = split(",", $map_extent);
         $coord = $this->enlargeExtent($coord, $width, $height, $neededWidth, $neededHeight);
         $obj->set("BBOX", implode(",", $coord));
         $url[$i] = $obj->url;
     }
     //get image
     $urls = implode("___", $url);
     $this->weldMaps2PNG($urls, $filename, $encode);
     //rotate image
     $imagick = new Imagick();
     $imagick->readImage($filename);
     $imagick->rotateImage(new ImagickPixel(), $angle);
     //get the new dimensions
     $imgWidth = $imagick->getImageWidth();
     $imgHeight = $imagick->getImageHeight();
     //crop empty areas
     $imagick->cropImage($width, $height, ($imgWidth - $width) / 2, ($imgHeight - $height) / 2);
     //write modified image
     $imagick->writeImage();
     $image = imagecreatefrompng($filename);
     imagepng($image, $filename);
 }
 /**
  * @ref http://www.b-prep.com/blog/?p=1764
  *
  * @param \Imagick $image
  * @return \Imagick
  */
 private function fixImageOrientation($image)
 {
     $orientation = $image->getImageOrientation();
     switch ($orientation) {
         case \Imagick::ORIENTATION_UNDEFINED:
             break;
         case \Imagick::ORIENTATION_TOPLEFT:
             break;
         case \Imagick::ORIENTATION_TOPRIGHT:
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_BOTTOMRIGHT:
             $image->rotateImage(new \ImagickPixel(), 180);
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_BOTTOMLEFT:
             $image->rotateImage(new \ImagickPixel(), 180);
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_LEFTTOP:
             $image->rotateImage(new \ImagickPixel(), 90);
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_RIGHTTOP:
             $image->rotateImage(new \ImagickPixel(), 90);
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_RIGHTBOTTOM:
             $image->rotateImage(new \ImagickPixel(), 270);
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_LEFTBOTTOM:
             $image->rotateImage(new \ImagickPixel(), 270);
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
     }
     return $image;
 }
예제 #21
0
 /**
  * Performs optimized gradient fill for non-opaque linear gradients
  *
  * @param Linear $fill
  */
 private function applyFastLinear(Linear $fill)
 {
     $gradient = new \Imagick();
     $size = $this->getSize();
     $color = sprintf('gradient:%s-%s', (string) $fill->getStart(), (string) $fill->getEnd());
     if ($fill instanceof Horizontal) {
         $gradient->newPseudoImage($size->getHeight(), $size->getWidth(), $color);
         $gradient->rotateImage(new \ImagickPixel(), 90);
     } else {
         $gradient->newPseudoImage($size->getWidth(), $size->getHeight(), $color);
     }
     $this->imagick->compositeImage($gradient, \Imagick::COMPOSITE_OVER, 0, 0);
     $gradient->clear();
     $gradient->destroy();
 }
예제 #22
0
/**
 * Fixes image orientation.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param array $file The image file.
 * @return mixed Image file.
 */
function geodir_exif($file)
{
    //This line reads the EXIF data and passes it into an array
    $file['file'] = $file['tmp_name'];
    if ($file['type'] == "image/jpg" || $file['type'] == "image/jpeg" || $file['type'] == "image/pjpeg") {
    } else {
        return $file;
    }
    if (!function_exists('read_exif_data')) {
        return $file;
    }
    $exif = read_exif_data($file['file']);
    //We're only interested in the orientation
    $exif_orient = isset($exif['Orientation']) ? $exif['Orientation'] : 0;
    $rotateImage = 0;
    //We convert the exif rotation to degrees for further use
    if (6 == $exif_orient) {
        $rotateImage = 90;
        $imageOrientation = 1;
    } elseif (3 == $exif_orient) {
        $rotateImage = 180;
        $imageOrientation = 1;
    } elseif (8 == $exif_orient) {
        $rotateImage = 270;
        $imageOrientation = 1;
    }
    //if the image is rotated
    if ($rotateImage) {
        //WordPress 3.5+ have started using Imagick, if it is available since there is a noticeable difference in quality
        //Why spoil beautiful images by rotating them with GD, if the user has Imagick
        if (class_exists('Imagick')) {
            $imagick = new Imagick();
            $imagick->readImage($file['file']);
            $imagick->rotateImage(new ImagickPixel(), $rotateImage);
            $imagick->setImageOrientation($imageOrientation);
            $imagick->writeImage($file['file']);
            $imagick->clear();
            $imagick->destroy();
        } else {
            //if no Imagick, fallback to GD
            //GD needs negative degrees
            $rotateImage = -$rotateImage;
            switch ($file['type']) {
                case 'image/jpeg':
                    $source = imagecreatefromjpeg($file['file']);
                    $rotate = imagerotate($source, $rotateImage, 0);
                    imagejpeg($rotate, $file['file']);
                    break;
                case 'image/png':
                    $source = imagecreatefrompng($file['file']);
                    $rotate = imagerotate($source, $rotateImage, 0);
                    imagepng($rotate, $file['file']);
                    break;
                case 'image/gif':
                    $source = imagecreatefromgif($file['file']);
                    $rotate = imagerotate($source, $rotateImage, 0);
                    imagegif($rotate, $file['file']);
                    break;
                default:
                    break;
            }
        }
    }
    // The image orientation is fixed, pass it back for further processing
    return $file;
}
예제 #23
0
파일: Image.php 프로젝트: momoim/momo-api
 /**
  * 旋转图片
  */
 public static function rotate_by_degree($file_path, $degree)
 {
     $image = new Imagick($file_path);
     $image->rotateImage(new ImagickPixel(), $degree);
     $image->writeImage($file_path);
 }
예제 #24
0
 public function adjustFile($path, $info)
 {
     # Check dependencies
     self::dependencies(isset($path, $info));
     # Call plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     if (extension_loaded('imagick') && $this->settings['imagick'] === '1') {
         $rotateImage = 0;
         switch ($info['orientation']) {
             case 3:
                 $rotateImage = 180;
                 $imageOrientation = 1;
                 break;
             case 6:
                 $rotateImage = 90;
                 $imageOrientation = 1;
                 break;
             case 8:
                 $rotateImage = 270;
                 $imageOrientation = 1;
                 break;
         }
         if ($rotateImage !== 0) {
             $image = new Imagick();
             $image->readImage($path);
             $image->rotateImage(new ImagickPixel(), $rotateImage);
             $image->setImageOrientation($imageOrientation);
             $image->writeImage($path);
             $image->clear();
             $image->destroy();
         }
     } else {
         $newWidth = $info['width'];
         $newHeight = $info['height'];
         $process = false;
         $sourceImg = imagecreatefromjpeg($path);
         switch ($info['orientation']) {
             case 2:
                 # mirror
                 # not yet implemented
                 break;
             case 3:
                 $process = true;
                 $sourceImg = imagerotate($sourceImg, -180, 0);
                 break;
             case 4:
                 # rotate 180 and mirror
                 # not yet implemented
                 break;
             case 5:
                 # rotate 90 and mirror
                 # not yet implemented
                 break;
             case 6:
                 $process = true;
                 $sourceImg = imagerotate($sourceImg, -90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 break;
             case 7:
                 # rotate -90 and mirror
                 # not yet implemented
                 break;
             case 8:
                 $process = true;
                 $sourceImg = imagerotate($sourceImg, 90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 break;
         }
         # Need to adjust photo?
         if ($process === true) {
             # Recreate photo
             $newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
             imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
             imagejpeg($newSourceImg, $path, 100);
             # Free memory
             imagedestroy($sourceImg);
             imagedestroy($newSourceImg);
         }
     }
     # Call plugins
     $this->plugins(__METHOD__, 1, func_get_args());
     return true;
 }
예제 #25
0
 /**
  * Corrects orientation of an image
  * @param \Imagick $im
  */
 private function correctOrientation(\Imagick &$im)
 {
     switch ($im->getImageOrientation()) {
         case \Imagick::ORIENTATION_TOPRIGHT:
             $im->flipImage();
             break;
         case \Imagick::ORIENTATION_BOTTOMRIGHT:
             $im->rotateImage(new \ImagickPixel("none"), 180);
             break;
         case \Imagick::ORIENTATION_BOTTOMLEFT:
             $im->rotateImage(new \ImagickPixel("none"), 180);
             $im->flipImage();
             break;
         case \Imagick::ORIENTATION_LEFTTOP:
             $im->rotateImage(new \ImagickPixel("none"), 90);
             $im->flipImage();
             break;
         case \Imagick::ORIENTATION_RIGHTTOP:
             $im->rotateImage(new \ImagickPixel("none"), 90);
             break;
         case \Imagick::ORIENTATION_RIGHTBOTTOM:
             $im->rotateImage(new \ImagickPixel("none"), -90);
             $im->flipImage();
             break;
         case \Imagick::ORIENTATION_LEFTBOTTOM:
             $im->rotateImage(new \ImagickPixel("none"), -90);
             break;
         default:
     }
 }
function image_rotation($im, $angle, $crop = false)
{
    $fonction = array('image_rotation', func_get_args());
    $image = _image_valeurs_trans($im, "rot-{$angle}-{$crop}", "png", $fonction);
    if (!$image) {
        return "";
    }
    $im = $image["fichier"];
    $dest = $image["fichier_dest"];
    $creer = $image["creer"];
    if ($creer) {
        $effectuer_gd = true;
        if (method_exists('Imagick', 'rotateImage')) {
            $imagick = new Imagick();
            $imagick->readImage($im);
            $imagick->rotateImage(new ImagickPixel('none'), $angle);
            $imagick->writeImage($dest);
            $effectuer_gd = false;
        } else {
            if ($GLOBALS['meta']['image_process'] == "convert") {
                if (_CONVERT_COMMAND != '') {
                    @define('_CONVERT_COMMAND', 'convert');
                    @define('_ROTATE_COMMAND', _CONVERT_COMMAND . ' -background none -rotate %t %src %dest');
                } else {
                    @define('_ROTATE_COMMAND', '');
                }
                if (_ROTATE_COMMAND !== '') {
                    $commande = str_replace(array('%t', '%src', '%dest'), array($angle, escapeshellcmd($im), escapeshellcmd($dest)), _ROTATE_COMMAND);
                    spip_log($commande);
                    exec($commande);
                    if (file_exists($dest)) {
                        $effectuer_gd = false;
                    }
                }
            } elseif (function_exists('imagick_rotate')) {
                $handle = imagick_readimage($im);
                if ($handle && imagick_isopaqueimage($handle)) {
                    imagick_setfillcolor($handle, 'transparent');
                    imagick_rotate($handle, $angle);
                    imagick_writeimage($handle, $dest);
                    $effectuer_gd = false;
                }
            }
        }
        if ($effectuer_gd) {
            // Creation de l'image en deux temps
            // de facon a conserver les GIF transparents
            $im = $image["fonction_imagecreatefrom"]($im);
            imagepalettetotruecolor($im);
            $im = image_RotateBicubic($im, $angle, true);
            _image_gd_output($im, $image);
            imagedestroy($im);
        }
    }
    list($src_y, $src_x) = taille_image($dest);
    return _image_ecrire_tag($image, array('src' => $dest, 'width' => $src_x, 'height' => $src_y));
}
예제 #27
0
 /**
  * Rotates the image's
  *
  * @param int $angle
  *
  * @return Imagick
  */
 public function rotate($angle)
 {
     $this->image->rotateImage(new \ImagickPixel('#00000000'), $angle);
     $this->operations[] = 'rotate' . $angle;
     return $this;
 }
예제 #28
0
 /**
  * @param File $file
  * @param array $params Rotate parameters.
  *   'rotation' clockwise rotation in degrees, allowed are multiples of 90
  * @since 1.21
  * @return bool
  */
 public function rotate($file, $params)
 {
     global $wgImageMagickConvertCommand;
     $rotation = ($params['rotation'] + $this->getRotation($file)) % 360;
     $scene = false;
     $scaler = $this->getScalerType(null, false);
     switch ($scaler) {
         case 'im':
             $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) . " " . wfEscapeShellArg($this->escapeMagickInput($params['srcPath'], $scene)) . " -rotate " . wfEscapeShellArg("-{$rotation}") . " " . wfEscapeShellArg($this->escapeMagickOutput($params['dstPath']));
             wfDebug(__METHOD__ . ": running ImageMagick: {$cmd}\n");
             $retval = 0;
             $err = wfShellExecWithStderr($cmd, $retval);
             if ($retval !== 0) {
                 $this->logErrorForExternalProcess($retval, $err, $cmd);
                 return new MediaTransformError('thumbnail_error', 0, 0, $err);
             }
             return false;
         case 'imext':
             $im = new Imagick();
             $im->readImage($params['srcPath']);
             if (!$im->rotateImage(new ImagickPixel('white'), 360 - $rotation)) {
                 return new MediaTransformError('thumbnail_error', 0, 0, "Error rotating {$rotation} degrees");
             }
             $result = $im->writeImage($params['dstPath']);
             if (!$result) {
                 return new MediaTransformError('thumbnail_error', 0, 0, "Unable to write image to {$params['dstPath']}");
             }
             return false;
         default:
             return new MediaTransformError('thumbnail_error', 0, 0, "{$scaler} rotation not implemented");
     }
 }
예제 #29
0
 public function adjustFile($path, $info)
 {
     # Function rotates and flips a photo based on its EXIF orientation
     # Excepts the following:
     # (string) $path = Path to the photo-file
     # (array) $info = ['orientation', 'width', 'height']
     # Returns the following
     # (array) $info = ['orientation', 'width', 'height'] = Success
     # (boolean) false = Failure
     # Check dependencies
     self::dependencies(isset($path, $info));
     # Call plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     $swapSize = false;
     if (extension_loaded('imagick') && $this->settings['imagick'] === '1') {
         $rotateImage = 0;
         switch ($info['orientation']) {
             case 3:
                 $rotateImage = 180;
                 break;
             case 6:
                 $rotateImage = 90;
                 $swapSize = true;
                 break;
             case 8:
                 $rotateImage = 270;
                 $swapSize = true;
                 break;
             default:
                 return false;
                 break;
         }
         if ($rotateImage !== 0) {
             $image = new Imagick();
             $image->readImage($path);
             $image->rotateImage(new ImagickPixel(), $rotateImage);
             $image->setImageOrientation(1);
             $image->writeImage($path);
             $image->clear();
             $image->destroy();
         }
     } else {
         $newWidth = $info['width'];
         $newHeight = $info['height'];
         $sourceImg = imagecreatefromjpeg($path);
         switch ($info['orientation']) {
             case 2:
                 # mirror
                 # not yet implemented
                 return false;
                 break;
             case 3:
                 $process = true;
                 $sourceImg = imagerotate($sourceImg, -180, 0);
                 break;
             case 4:
                 # rotate 180 and mirror
                 # not yet implemented
                 return false;
                 break;
             case 5:
                 # rotate 90 and mirror
                 # not yet implemented
                 return false;
                 break;
             case 6:
                 $process = true;
                 $sourceImg = imagerotate($sourceImg, -90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 $swapSize = true;
                 break;
             case 7:
                 # rotate -90 and mirror
                 # not yet implemented
                 return false;
                 break;
             case 8:
                 $process = true;
                 $sourceImg = imagerotate($sourceImg, 90, 0);
                 $newWidth = $info['height'];
                 $newHeight = $info['width'];
                 $swapSize = true;
                 break;
             default:
                 return false;
                 break;
         }
         # Recreate photo
         $newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
         imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
         imagejpeg($newSourceImg, $path, 100);
         # Free memory
         imagedestroy($sourceImg);
         imagedestroy($newSourceImg);
     }
     # Call plugins
     $this->plugins(__METHOD__, 1, func_get_args());
     # SwapSize should be true when the image has been rotated
     # Return new dimensions in this case
     if ($swapSize === true) {
         $swapSize = $info['width'];
         $info['width'] = $info['height'];
         $info['height'] = $swapSize;
     }
     return $info;
 }
예제 #30
0
 function rotate($d)
 {
     $d = $d * -1;
     $color_transparent = new ImagickPixel("transparent");
     //透明色
     if ($this->image_type == 'GIF') {
         $dest = new Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($frame, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             $tmp->rotateImage($color_transparent, $d);
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($frame->getImageDelay());
             $dest->setImageDispose($frame->getImageDispose());
         }
         $dest->coalesceImages();
         $this->image->destroy();
         $this->image = $dest;
     } else {
         $this->image->rotateImage($color_transparent, $d);
     }
 }