當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Imagick::rotateimage方法代碼示例

本文整理匯總了PHP中Imagick::rotateimage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::rotateimage方法的具體用法?PHP Imagick::rotateimage怎麽用?PHP Imagick::rotateimage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imagick的用法示例。


在下文中一共展示了Imagick::rotateimage方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: rotate

 /**
  * {@inheritdoc}
  *
  * @return ImageInterface
  */
 public function rotate($angle, ColorInterface $background = null)
 {
     $color = $background ? $background : $this->palette->color('fff');
     try {
         $pixel = $this->getColor($color);
         $this->imagick->rotateimage($pixel, $angle);
         $pixel->clear();
         $pixel->destroy();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Rotate operation failed', $e->getCode(), $e);
     }
     return $this;
 }
開發者ID:easytp,項目名稱:easytp,代碼行數:18,代碼來源:Image.class.php

示例2: transform

 /**
  * Apply transformations (rotate/crop) to an image
  *
  * ```
  * $data = [
  *     'rotate' => 90,
  *     'width' => 200,
  *     'height' => 300,
  *     'x' => 20,
  *     'y' => 50,
  * ];
  * ```
  *
  * @param \Cake\Datasource\EntityTrait $image the entity being transformed
  * @param array $data the transformation information
  * @return void
  */
 public function transform(Entity $image, array $data = null)
 {
     $sourcePath = $image->sourcePath;
     $image->filename = uniqid() . '.' . $image->ext;
     $result = $this->_table->save($image);
     if ($result) {
         $imagick = new \Imagick($sourcePath);
         if (!is_null($data)) {
             $imagick->rotateimage('#000', $data['rotate']);
             $imagick->cropImage($data['width'], $data['height'], $data['x'], $data['y']);
         }
         $imagick->writeImage($result->sourcePath);
         unlink($sourcePath);
     }
 }
開發者ID:gintonicweb,項目名稱:images,代碼行數:32,代碼來源:ImageBehavior.php

示例3: autoOrient

 /**
  * Applies EXIF orientation metadata to pixel data and removes the EXIF rotation
  *
  * @access protected
  */
 protected function autoOrient()
 {
     // apply EXIF orientation to pixel data
     switch ($this->originalImage->getImageOrientation()) {
         case \Imagick::ORIENTATION_BOTTOMRIGHT:
             $this->originalImage->rotateimage('#000', 180);
             // rotate 180 degrees
             break;
         case \Imagick::ORIENTATION_RIGHTTOP:
             $this->originalImage->rotateimage('#000', 90);
             // rotate 90 degrees CW
             break;
         case \Imagick::ORIENTATION_LEFTBOTTOM:
             $this->originalImage->rotateimage('#000', -90);
             // rotate 90 degrees CCW
             break;
     }
     // reset EXIF orientation
     $this->originalImage->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
 }
開發者ID:nexusthemes,項目名稱:crop,代碼行數:25,代碼來源:Crop.php

示例4: fixImageRotationOld

 static function fixImageRotationOld($file)
 {
     $degrees = NULL;
     $image = imagecreatefromstring(file_get_contents($file));
     try {
         $exif = exif_read_data($file);
     } catch (Exception $exp) {
         return;
     }
     if ($exif) {
         $exif = \exif_read_data($file, 'ANY_TAG');
         if (isset($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 3:
                     $degrees = 180;
                     break;
                 case 6:
                     $degrees = 90;
                     break;
                 case 8:
                     $degrees = -90;
                     break;
             }
         }
         if (class_exists("\\Imagick")) {
             try {
                 $img = new \Imagick($file);
                 $img->stripImage();
                 if ($degrees) {
                     $img->rotateimage("#ffffff", $degrees);
                 }
                 $img->writeImage($file);
                 $img->clear();
                 $img->destroy();
             } catch (Exception $e) {
             }
         }
         return;
     }
 }
開發者ID:socialapparatus,項目名稱:socialapparatus,代碼行數:40,代碼來源:Image.php

示例5: gradientRight

 private function gradientRight()
 {
     $imagick = new \Imagick();
     $imagick->newpseudoimage($this->width, $this->height, 'gradient:black-white');
     $imagick->rotateimage('black', -90);
     return $imagick;
 }
開發者ID:sdmmember,項目名稱:Imagick-demos,代碼行數:7,代碼來源:composite.php

示例6: actionGo

 public function actionGo()
 {
     if ($_FILES["file"]["error"] > 0) {
         echo "Error: " . $_FILES["file"]["error"] . "<br>";
     } else {
         $f = $_POST['filter'];
         $capPhoto = $_POST['capPhoto'];
         $min_rand = rand(0, 1000);
         $max_rand = rand(100000000000, 10000000000000000);
         $name_file = rand($min_rand, $max_rand);
         //this part is for creating random name for image
         $ext = end(explode(".", $_FILES["file"]["name"]));
         //gets extension
         $file = Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext;
         move_uploaded_file($_FILES["file"]["tmp_name"], Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext);
         chmod($file, 0777);
         if (exif_imagetype($file) == IMAGETYPE_JPEG) {
             $exif = exif_read_data($file);
             if (isset($exif['Orientation'])) {
                 $orientation = $exif['Orientation'];
                 if ($orientation == 6) {
                     $imz = new Imagick($file);
                     $imz->rotateimage("#FFF", 90);
                     $imz->writeImage($file);
                     chmod($file, 0777);
                 } else {
                     if ($orientation == 8) {
                         $imz = new Imagick($file);
                         $imz->rotateimage("#FFF", -90);
                         $imz->writeImage($file);
                         chmod($file, 0777);
                     }
                 }
             }
         }
         // Max vert or horiz resolution
         $maxsize = 1200;
         // create new Imagick object
         $image = new Imagick($file);
         // Resizes to whichever is larger, width or height
         if ($image->getImageHeight() <= $image->getImageWidth()) {
             // Resize image using the lanczos resampling algorithm based on width
             $image->resizeImage($maxsize, 0, Imagick::FILTER_LANCZOS, 1);
         } else {
             // Resize image using the lanczos resampling algorithm based on height
             $image->resizeImage(0, $maxsize, Imagick::FILTER_LANCZOS, 1);
         }
         // Set to use jpeg compression
         $image->setImageCompression(Imagick::COMPRESSION_JPEG);
         // Set compression level (1 lowest quality, 100 highest quality)
         $image->setImageCompressionQuality(75);
         // Strip out unneeded meta data
         $image->stripImage();
         // Writes resultant image to output directory
         $image->writeImage($file);
         // Destroys Imagick object, freeing allocated resources in the process
         $image->destroy();
         chmod($file, 0777);
         $filter = Instagraph::factory($file, $file);
         $filter->{$f}();
         // 320 Show Preview
         $immid = new Imagick($file);
         if ($immid->getimagewidth() > 320) {
             $immid->thumbnailImage(320, null);
             $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext);
             $immid->destroy();
             chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777);
         } else {
             $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext);
             $immid->destroy();
             chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777);
         }
         // null x 230 show last upload
         $imlast = new Imagick($file);
         $imlast->thumbnailimage(null, 230);
         $imlast->writeImage(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext);
         $imlast->destroy();
         chmod(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext, 0777);
         // 130 x 110 thumbmail
         $im = new Imagick($file);
         $im->thumbnailImage(130, 110);
         $im->writeImage(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext);
         chmod(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext, 0777);
         $im->destroy();
         $photo = new Photo();
         $photo->link = $file;
         $photo->fbid = Yii::app()->facebook->getUser();
         $photo->ip = $_SERVER['REMOTE_ADDR'];
         if ($photo->save()) {
             $id = $photo->id;
             if (isset($_POST['shareFB'])) {
                 $share = 1;
             } else {
                 $share = 0;
             }
             if ($share == 1) {
                 $cr = "\n" . "http://www.pla2gram.com/?p=" . $id . "&theater=1";
                 $capFB = $capPhoto . $cr;
                 // Post to Facebook
                 $args = array('message' => $capFB);
//.........這裏部分代碼省略.........
開發者ID:aommiez,項目名稱:pla2gram,代碼行數:101,代碼來源:SiteController.php

示例7: rotate

 /**
  * Rotate 90 degrees left
  * @param int $val
  * @return bool
  */
 public function rotate($val = 90)
 {
     $source = $this->_getTempEditorFullPath();
     $picture = new Imagick($source[0]);
     $picture->rotateimage(new ImagickPixel(), $val);
     $picture->writeImage($source[1]);
     $this->getRawEditorCache();
     return true;
 }
開發者ID:Cryde,項目名稱:sydney-core,代碼行數:14,代碼來源:Image.php

示例8: _thumb

 public function _thumb($thumbPath, $maxWidth, $maxHeight)
 {
     try {
         $im = new \Imagick();
         $im->readImage($this->path);
         switch ($this->orientation) {
             case \imagick::ORIENTATION_UNDEFINED:
                 // 0
             // 0
             case \imagick::ORIENTATION_TOPLEFT:
                 // 1 : no rotation
                 break;
             case \imagick::ORIENTATION_BOTTOMRIGHT:
                 // 3 : 180 deg
                 $im->rotateimage(new \ImagickPixel(), 180);
                 break;
             case \imagick::ORIENTATION_RIGHTTOP:
                 // 6 : 90 deg CW
                 $im->rotateimage(new \ImagickPixel(), 90);
                 break;
             case \imagick::ORIENTATION_LEFTBOTTOM:
                 // 8 : 90 deg CCW
                 $im->rotateimage(new \ImagickPixel(), -90);
                 break;
             default:
                 // we should never get here, this is checked in load() as well
                 die('Unsupported EXIF orientation');
         }
         // Now that it's auto-rotated, make sure the EXIF data is correct, so
         // thumbnailImage doesn't try to autorotate the image
         $im->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
         if ($im->getImageWidth() > $maxWidth || $im->getImageHeight() > $maxHeight) {
             $im->thumbnailImage($maxWidth, $maxHeight, true);
         }
         $w = $im->getImageWidth();
         $h = $im->getImageHeight();
         $im->setImageCompressionQuality(75);
         $im->stripImage();
         $im->writeImage($thumbPath);
         $im->destroy();
     } catch (Exception $e) {
         return $e->getMessage();
         # TODO: MAke sure this is handled!
     }
     return array($w, $h);
 }
開發者ID:omarjedhxxx44,項目名稱:croptool,代碼行數:46,代碼來源:Image.php

示例9: ImagickAutoRotateImage

 /**
  * Automatic rotation fix
  * 
  * @param \Imagick $image
  */
 public function ImagickAutoRotateImage(\Imagick $image)
 {
     $orientation = $image->getImageOrientation();
     switch ($orientation) {
         case \imagick::ORIENTATION_BOTTOMRIGHT:
             $image->rotateimage("#000", 180);
             // rotate 180 degrees
             break;
         case \imagick::ORIENTATION_RIGHTTOP:
             $image->rotateimage("#000", 90);
             // rotate 90 degrees CW
             break;
         case \imagick::ORIENTATION_LEFTBOTTOM:
             $image->rotateimage("#000", -90);
             // rotate 90 degrees CCW
             break;
     }
     $image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
 }
開發者ID:infoweb-internet-solutions,項目名稱:yii2-cms,代碼行數:24,代碼來源:Image.php

示例10: thumbnail


//.........這裏部分代碼省略.........
                 }
             }
             $handle->image_border_color = '#FFFFFF';
             $handle->image_border_opacity = 0;
         } else {
             // the image size is bigger than the requested width / height, we must resize it
             $handle->image_default_color = '#FFFFFF';
             $handle->image_resize = true;
             $handle->image_ratio_fill = true;
         }
         if ($border == 0) {
             $handle->image_border = false;
             $handle->image_ratio_no_zoom_in = false;
             if (!empty($item->focalpoint) && $handle->image_src_x > 0) {
                 $focalpoint = explode('#', $item->focalpoint);
                 $crop = array('top' => 0, 'right' => 0, 'bottom' => 0, 'left' => 0);
                 // calculate how the file will be scaled, by width or by height
                 if ($handle->image_src_x / $handle->image_x > $handle->image_src_y / $handle->image_y) {
                     // Y is ok, now crop extra space on X
                     $ratio = $handle->image_y / $handle->image_src_y;
                     $image_scaled_x = intval($handle->image_src_x * $ratio);
                     $crop['left'] = max(0, round(($image_scaled_x * ($focalpoint[1] / 100) - $handle->image_x / 2) / $ratio));
                     $crop['right'] = max(0, round(($image_scaled_x * ((100 - $focalpoint[1]) / 100) - $handle->image_x / 2) / $ratio));
                 } else {
                     // X is ok, now crop extra space on Y
                     $ratio = $handle->image_x / $handle->image_src_x;
                     $image_scaled_y = intval($handle->image_src_y * $ratio);
                     $crop['top'] = max(0, round(($image_scaled_y * ($focalpoint[0] / 100) - $handle->image_y / 2) / $ratio));
                     $crop['bottom'] = max(0, round(($image_scaled_y * ((100 - $focalpoint[0]) / 100) - $handle->image_y / 2) / $ratio));
                 }
                 $handle->image_precrop = array($crop['top'], $crop['right'], $crop['bottom'], $crop['left']);
             }
             $handle->image_ratio_crop = true;
             $handle->image_ratio_fill = true;
         }
         $handle->png_compression = 9;
         $handle->process(dirname($thumbnail));
         rename($handle->file_dst_pathname, $thumbnail);
         clearstatcache(true, $thumbnail);
         if (!file_exists($thumbnail) || filesize($thumbnail) < 1) {
             return NULL;
         }
         // try to recompress the png thumbnail file to achieve the minimum file size,
         // only if some extra apps are available
         if (extension_loaded('imagick')) {
             $im = new Imagick($thumbnail);
             $image_alpha_range = $im->getImageChannelRange(Imagick::CHANNEL_ALPHA);
             //$image_alpha_mean = $im->getImageChannelMean(Imagick::CHANNEL_ALPHA);
             $image_is_opaque = $image_alpha_range['minima'] == 0 && $image_alpha_range['maxima'] == 0;
             // autorotate image based on EXIF data
             $im_original = new Imagick($original);
             $orientation = $im_original->getImageOrientation();
             $im_original->clear();
             switch ($orientation) {
                 case imagick::ORIENTATION_BOTTOMRIGHT:
                     $im->rotateimage(new ImagickPixel('transparent'), 180);
                     // rotate 180 degrees
                     break;
                 case imagick::ORIENTATION_RIGHTTOP:
                     $im->rotateimage(new ImagickPixel('transparent'), 90);
                     // rotate 90 degrees CW
                     break;
                 case imagick::ORIENTATION_LEFTBOTTOM:
                     $im->rotateimage(new ImagickPixel('transparent'), -90);
                     // rotate 90 degrees CCW
                     break;
             }
             // Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
             $im->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
             if (!$image_is_opaque) {
                 $im->setImageFormat('PNG32');
                 // Force a full RGBA image format with full semi-transparency.
                 $im->setBackgroundColor(new ImagickPixel('transparent'));
                 $im->setImageCompression(Imagick::COMPRESSION_UNDEFINED);
                 $im->setImageCompressionQuality(0);
                 $im->writeimage($thumbnail);
             } else {
                 $im->setImageFormat('JPG');
                 // create an OPAQUE JPG file with the given quality (default 95%)
                 $im->setImageCompressionQuality($quality);
                 $im->writeimage($thumbnail_path_jpg);
                 @unlink($thumbnail);
                 $thumbnail = $thumbnail_path_jpg;
             }
         }
         /*
                    if(command_exists('pngquant')) // PNG Optimization: 8 bit with transparency
                    {
                        @shell_exec('pngquant -s1 --ext .pngquant '.$thumbnail);
                        if(file_exists($thumbnail.'.pngquant'))
                        {
                            unlink($thumbnail);
                            rename($thumbnail.'.pngquant', $thumbnail);
                        }
                    }
                    else*/
     }
     clearstatcache(true, $thumbnail);
     return $thumbnail;
 }
開發者ID:NavigateCMS,項目名稱:Navigate-CMS,代碼行數:101,代碼來源:file.class.php

示例11: createThali

 public function createThali($dishArray = array(), $is_thali, $w = 140, $h = 0)
 {
     Configure::write('debug', 2);
     ini_set("max_execution_time", -1);
     $thali1 = new Imagick("tmpl/img/thali-1.png");
     $thali2 = new Imagick("tmpl/img/thali-2.png");
     $thali3 = new Imagick("tmpl/img/thali-3.png");
     $mask_1 = new Imagick("tmpl/img/thali-mask2.png");
     $mask_2 = new Imagick("tmpl/img/thali-mask3.png");
     if (!is_array($dishArray)) {
         return false;
     }
     $mask_cnt = 0;
     foreach ($dishArray as $dish) {
         if ($mask_cnt > 1) {
             // Mask Locking (Modify if masks will be increased or decreased)
             break;
         }
         $dish = new Imagick($dish);
         $dish->scaleimage($thali1->getimagewidth(), $thali1->getimageheight());
         // Set As per bowl image
         if ($is_thali) {
             if ($mask_cnt == 1) {
                 $dish->rotateimage("#fff", 180);
             }
             $dish->compositeimage(new Imagick("tmpl/img/thali-mask" . ($mask_cnt + 2) . ".png"), \Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
             $dish->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
             $thali1->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
             $thali1->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
             $thali2->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
             $thali2->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
             $thali3->compositeimage($dish, \Imagick::COMPOSITE_ATOP, 0, 0, Imagick::CHANNEL_ALPHA);
             $thali3->mergeimagelayers(Imagick::LAYERMETHOD_COALESCE);
         } else {
             $thali3 = $dish;
         }
         $mask_cnt++;
     }
     $url = "files/thali_images/" . $this->randomString(6);
     $url_end = "-Thali.jpg";
     $result_urls = array();
     $thali1->setimageformat("jpg");
     $thali1->setImageFileName($result_urls[] = $url . "-0" . $url_end);
     $thali1->scaleimage($w, $h);
     if ($is_thali) {
         $thali2->writeimage();
     }
     $thali1->destroy();
     $thali2->setimageformat("jpg");
     $thali2->setImageFileName($result_urls[] = $url . "-1" . $url_end);
     $thali2->scaleimage($w, $h);
     if ($is_thali) {
         $thali2->writeimage();
     }
     $thali2->destroy();
     $thali3->setimageformat("jpg");
     $thali3->setImageFileName($result_urls[] = $url . "-2" . $url_end);
     $thali3->scaleimage($w, $h);
     $thali3->writeimage();
     $thali3->destroy();
     return $result_urls;
 }
開發者ID:ashutoshdev,項目名稱:pickmeals-web,代碼行數:62,代碼來源:CombinationsController.php

示例12: _rotatePhoto

 protected function _rotatePhoto($photoData, $image, $angle, $tempFile)
 {
     if (XenForo_Application::getOptions()->imageLibrary['class'] === 'imPecl') {
         $class = new Imagick($image);
         $class->rotateimage(new ImagickPixel(), 360 - $angle);
         $class->setimageformat($photoData['extension']);
         $success = $class->writeImages($tempFile, true);
         $class->destroy();
     } else {
         $gd = $this->createImageFromFile($image, self::$typeMap[$photoData['extension']]);
         if (!$gd) {
             return false;
         }
         $rotate = imagerotate($gd, $angle, imageColorAllocateAlpha($gd, 0, 0, 0, 127));
         $success = $this->outputImage($rotate, self::$typeMap[$photoData['extension']], $tempFile);
         imagedestroy($rotate);
         imagedestroy($gd);
     }
     return $success;
 }
開發者ID:Sywooch,項目名稱:forums,代碼行數:20,代碼來源:PhotoData.php

示例13: strtolower

         $fileExt = strtolower($fileExt);
         if (in_array($fileExt, array("png", "jpeg", "gif", "jpg"))) {
             $fileType = "image/" . $fileExt;
         }
     }
 }
 if (isset($fileType)) {
     try {
         $img = new Imagick($_FILES["imagefile"]["tmp_name"]);
     } catch (ImagickException $e) {
         return new Response("Invalid image", 500);
     }
     $orientation = $img->getImageOrientation();
     switch ($orientation) {
         case imagick::ORIENTATION_BOTTOMRIGHT:
             $img->rotateimage("#000", 180);
             // rotate 180 degrees
             break;
         case imagick::ORIENTATION_RIGHTTOP:
             $img->rotateimage("#000", 90);
             // rotate 90 degrees CW
             break;
         case imagick::ORIENTATION_LEFTBOTTOM:
             $img->rotateimage("#000", -90);
             // rotate 90 degrees CCW
             break;
     }
     // Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
     $img->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
     // Save originals when file type is gif
     // TODO resize GIFs
開發者ID:holtchesley,項目名稱:Zeega-Media-Server,代碼行數:31,代碼來源:app.php

示例14: init

 function init()
 {
     //generate image
     $width = 256;
     $height = 256;
     /* Instanciate and read the image in */
     $im = new Imagick(base64_decode($_GET['uri']));
     /* Fit the image into $width x $height box
        The third parameter fits the image into a "bounding box" */
     $im->thumbnailImage($width, $height, true);
     /* Create a canvas with the desired color */
     $canvas = new Imagick();
     $canvas->newImage($width, $height, '#f2e6d8', 'png');
     /* Get the image geometry */
     $geometry = $im->getImageGeometry();
     $im->rotateimage('#f2e6d8', 180);
     /* The overlay x and y coordinates */
     $x = ($width - $geometry['width']) / 2;
     $y = ($height - $geometry['height']) / 2;
     /* Composite on the canvas  */
     $canvas->compositeImage($im, imagick::COMPOSITE_OVER, $x, $y);
     /* Output the image */
     header("Content-Type: image/png");
     echo $canvas;
     exit;
 }
開發者ID:bouras20122012,項目名稱:hack4europe3d,代碼行數:26,代碼來源:action.php


注:本文中的Imagick::rotateimage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。