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


PHP Imagick::cropImage方法代碼示例

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


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

示例1: serverAction

 public function serverAction(Request $request)
 {
     $fileName = $request->get('fileName');
     $points = $request->get('transform');
     $sizes = $this->getSizes();
     $fileFullName = $sizes[0]['dir'] . $fileName;
     try {
         $image = new \Imagick($fileFullName);
     } catch (\ImagickException $e) {
         return new JsonResponse(array('success' => false, 'errorMessage' => 'На сервере не найден файл'));
     }
     $finalScale = $sizes[0]['width'] / $sizes[0]['mediumWidth'];
     for ($i = 0; $i <= 5; $i++) {
         $points[$i] *= $finalScale;
     }
     $image->distortImage(\Imagick::DISTORTION_AFFINEPROJECTION, $points, TRUE);
     $image->cropImage($sizes[0]['width'], $sizes[0]['height'], 0, 0);
     $hashFile = md5_file($fileFullName);
     $fileName = $hashFile . '.jpg';
     foreach ($sizes as $size) {
         $imgFullName = $size['dir'] . $fileName;
         $image->thumbnailImage($size['width'], $size['height'], TRUE);
         $image->writeimage($imgFullName);
         if (!file_exists($imgFullName)) {
             $image->writeimage($imgFullName);
         }
     }
     return new JsonResponse(array('success' => true, 'fileName' => $fileName));
 }
開發者ID:binser,項目名稱:hookah.dev,代碼行數:29,代碼來源:PhotoController.php

示例2: _crop

 protected function _crop($width, $height, $offset_x, $offset_y)
 {
     if ($this->im->cropImage($width, $height, $offset_x, $offset_y)) {
         $this->width = $this->im->getImageWidth();
         $this->height = $this->im->getImageHeight();
         return true;
     }
     return false;
 }
開發者ID:navi8602,項目名稱:wa-shop-ppg,代碼行數:9,代碼來源:waImageImagick.class.php

示例3: crop

 /**
  * @see AbstractImage::crop
  */
 public function crop($iX, $iY, $iWidth, $iHeight)
 {
     //Be sure that the requested crop is inside the current image
     if ($iX + $iWidth > $this->width || $iY + $iHeight > $this->height) {
         throw new Exception('Crop area requested is outside the current picture !!');
     }
     $this->resource->cropImage($iWidth, $iHeight, $iX, $iY);
     $this->width = $iWidth;
     $this->height = $iHeight;
 }
開發者ID:rjoya,項目名稱:CDNThumbnailer,代碼行數:13,代碼來源:ImagickImage.php

示例4: crop

 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::crop()
  */
 public function crop(PointInterface $start, BoxInterface $size)
 {
     if (!$start->in($size)) {
         throw new OutOfBoundsException('Crop coordinates must start at ' . 'minimum 0, 0 position from top left corner, crop height and ' . 'width must be positive integers and must not exceed the ' . 'current image borders');
     }
     try {
         $this->imagick->cropImage($size->getWidth(), $size->getHeight(), $start->getX(), $start->getY());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Crop operation failed', $e->getCode(), $e);
     }
     return $this;
 }
開發者ID:nicodmf,項目名稱:Imagine,代碼行數:16,代碼來源:Image.php

示例5: create_thumb

function create_thumb($source_file, $thumb_file, $edge = THUMBNAIL_CROP_EDGE, &$src_w = NULL, &$src_h = NULL)
{
    $composite_img = new Imagick($source_file);
    $blank_img = new Imagick();
    $src_w = $composite_img->getImageWidth();
    $src_h = $composite_img->getImageHeight();
    if ($src_h > $edge && $src_w > $edge) {
        $composite_img->cropThumbnailImage($edge, $edge);
        $composite_img->setImageFormat('jpeg');
        $composite_img->writeImage($thumb_file);
        $composite_img->clear();
        $blank_img = $composite_img;
    } else {
        $blank_img->newImage($edge, $edge, new ImagickPixel('#DEF'), "jpg");
        if ($src_w > $src_h) {
            $crop_x = $src_w / 2 - $edge / 2;
            $crop_y = 0;
            $offset_x = 0;
            $offset_y = $edge / 2 - $src_h / 2;
        } else {
            $crop_x = 0;
            $crop_y = $src_h / 2 - $edge / 2;
            $offset_x = $edge / 2 - $src_w / 2;
            $offset_y = 0;
        }
        $composite_img->cropImage($edge, $edge, $crop_x, $crop_y);
        $blank_img->compositeImage($composite_img, Imagick::COMPOSITE_OVER, $offset_x, $offset_y);
        $blank_img->setImageFormat('jpeg');
        $blank_img->writeImage($thumb_file);
        $blank_img->clear();
    }
    return $blank_img;
}
開發者ID:hoogle,項目名稱:ttt,代碼行數:33,代碼來源:index.php

示例6: crop

 /**
  * Crops Image.
  *
  * @since 3.5.0
  * @access public
  *
  * @param int  $src_x The start x position to crop from.
  * @param int  $src_y The start y position to crop from.
  * @param int  $src_w The width to crop.
  * @param int  $src_h The height to crop.
  * @param int  $dst_w Optional. The destination width.
  * @param int  $dst_h Optional. The destination height.
  * @param bool $src_abs Optional. If the source crop points are absolute.
  * @return bool|WP_Error
  */
 public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false)
 {
     if ($src_abs) {
         $src_w -= $src_x;
         $src_h -= $src_y;
     }
     try {
         $this->image->cropImage($src_w, $src_h, $src_x, $src_y);
         $this->image->setImagePage($src_w, $src_h, 0, 0);
         if ($dst_w || $dst_h) {
             // If destination width/height isn't specified, use same as
             // width/height from source.
             if (!$dst_w) {
                 $dst_w = $src_w;
             }
             if (!$dst_h) {
                 $dst_h = $src_h;
             }
             $this->image->scaleImage($dst_w, $dst_h);
             return $this->update_size();
         }
     } catch (Exception $e) {
         return new WP_Error('image_crop_error', $e->getMessage());
     }
     return $this->update_size();
 }
開發者ID:sonvq,項目名稱:passioninvestment,代碼行數:41,代碼來源:class-wp-image-editor-imagick.php

示例7: drawTriangleStrip

 /**
  * Draws the triangle strip for the signature
  *
  * @param string $hexColour Hexadecimal colour value for the whole card
  */
 public function drawTriangleStrip($hexColour)
 {
     // The base for the triangles strip, to be drawn over the plain
     $darkTriangles = isset($_GET['darktriangles']);
     $backArea = new ImagickDraw();
     $backArea->setFillColor(new ImagickPixel($hexColour));
     $backArea->rectangle(self::SIG_MARGIN + self::SIG_STROKE_WIDTH, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, $this->baseWidth - self::SIG_STROKE_WIDTH + self::SIG_STROKE_WIDTH / 2 + 1, self::TRIANGLE_STRIP_HEIGHT - self::SIG_STROKE_WIDTH + self::SIG_ROUNDING * 4);
     $this->canvas->drawImage($backArea);
     $originalTriangles = new Imagick(self::IMG_TRIANGLES);
     $originalTriangles->cropImage($this->baseWidth, $this->baseHeight, $this->baseWidth / 2, $this->baseHeight / 2);
     $triangles = new Imagick();
     $triangles->newImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, new ImagickPixel($hexColour));
     $triangles = $triangles->textureImage($originalTriangles);
     // The gradient to draw over the triangles
     $trianglesGradient1 = new Imagick();
     $trianglesGradient1->newPseudoImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, 'gradient:' . 'none' . '-' . $hexColour);
     $trianglesGradient1->setImageOpacity(0.6);
     // The second gradient to draw over the triangles
     $trianglesGradient2 = new Imagick();
     $trianglesGradient2->newPseudoImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, 'gradient:' . '#4a4a4a' . '-' . '#313131');
     // Composite the black and white gradient onto the triangles
     $triangles->compositeImage($trianglesGradient2, Imagick::COMPOSITE_OVERLAY, 0, 0);
     $triangles->setImageOpacity($darkTriangles ? 0.2 : 0.1);
     // Composite the triangles onto the base
     $this->canvas->compositeImage($triangles, Imagick::COMPOSITE_DEFAULT, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 1.5);
     // Composite the triangles gradient onto the base
     $this->canvas->compositeImage($trianglesGradient1, Imagick::COMPOSITE_DEFAULT, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 1.5);
 }
開發者ID:BTCTaras,項目名稱:osusig,代碼行數:33,代碼來源:CardRegular.php

示例8: thumbImage

 public static function thumbImage($imgPath, $width, $height, $blur = 1, $bestFit = 0, $cropZoom = 1)
 {
     $dir = dirname($imgPath);
     $imagick = new \Imagick(realpath($imgPath));
     if ($imagick->getImageHeight() > $imagick->getImageWidth()) {
         $w = $width;
         $h = 0;
     } else {
         $h = $height;
         $w = 0;
     }
     $imagick->resizeImage($w, $h, $imagick::DISPOSE_UNDEFINED, $blur, $bestFit);
     $cropWidth = $imagick->getImageWidth();
     $cropHeight = $imagick->getImageHeight();
     if ($cropZoom) {
         $imagick->cropImage($width, $height, ($imagick->getImageWidth() - $width) / 2, ($imagick->getImageHeight() - $height) / 2);
     }
     $direct = 'thumbs/';
     $pathToWrite = $dir . "/" . $direct;
     //var_dump($pathToWrite);
     if (!file_exists($pathToWrite)) {
         mkdir($pathToWrite, 0777, true);
     }
     $newImageName = 'thumb_' . basename($imgPath);
     //var_dump($newImageName);
     $imagick->writeImage($pathToWrite . 'thumb_' . basename($imgPath));
     return $pathToWrite . $newImageName;
 }
開發者ID:Snuchycovich,項目名稱:ExifGallery,代碼行數:28,代碼來源:UploadManager.php

示例9: crop

 public function crop(ImageInterface $image, Size $sizeDest, Point $cropIniPoint = null, $middleCrop = true)
 {
     $imagick = new \Imagick($image->getPath());
     $widthSrc = $imagick->getImageWidth();
     $heightSrc = $imagick->getImageHeight();
     $widthDest = $sizeDest->getWidth();
     $heightDest = $sizeDest->getHeight();
     $cropX = 0;
     $cropY = 0;
     if ($middleCrop) {
         $cropX = ($widthSrc - $widthDest) / 2;
         $cropY = ($heightSrc - $heightDest) / 2;
     } else {
         if (isset($cropIniPoint)) {
             $cropX = $cropIniPoint->getX();
             $cropY = $cropIniPoint->getY();
         }
     }
     $imagick = new \Imagick($image->getPath());
     $imagick->cropImage($widthDest, $heightDest, $cropX, $cropY);
     $addToName = "_croped_" . $widthDest . "x" . $heightDest;
     list($name, $extension) = explode(".", $image->getOriginalName());
     list($path, $extension) = explode(".", $image->getPath());
     $newPath = $path . $addToName . "." . $extension;
     $newName = $name . $addToName . "." . $extension;
     $newImageSize = new Size($imagick->getImageWidth(), $imagick->getImageHeight());
     $imagick->writeImage($newPath);
     return $this->ImagickToImage($imagick, $image, $newPath, $newName, $newImageSize);
 }
開發者ID:vzaramel,項目名稱:Arkivar,代碼行數:29,代碼來源:ImagickImageManipulator.php

示例10: makeCover

 /**
  * makeCover - For shortcuts/gallery covers
  */
 public static function makeCover($sourceImg, $destImg)
 {
     $image = new Imagick($sourceImg);
     $w_orig = $image->getImageWidth();
     $h_orig = $image->getImageHeight();
     $w_new = SmIMAGE;
     $h_new = SmIMAGE * COVERASPECT;
     $ratio_orig = $h_orig / $w_orig;
     if ($ratio_orig == COVERASPECT) {
         // Only resize
         $image->resizeImage($w_new, $h_new, Imagick::FILTER_CATROM, 1, TRUE);
     } else {
         if ($ratio_orig >= COVERASPECT) {
             // Taller than target
             $w_temp = $w_new;
             $h_temp = $w_new * $ratio_orig;
             $w_center = 0;
             $h_center = ($h_temp - $h_new) / 2;
         } else {
             // Wider than target
             $w_temp = $h_new / $ratio_orig;
             $h_temp = $h_new;
             $w_center = ($w_temp - $w_new) / 2;
             $h_center = 0;
         }
         $image->resizeImage($w_temp, $h_temp, Imagick::FILTER_CATROM, 1, TRUE);
         $image->cropImage($w_new, $h_new, $w_center, $h_center);
     }
     $image->setImageCompression(Imagick::COMPRESSION_JPEG);
     $image->setImageCompressionQuality(80);
     $image->writeImage($destImg);
     $image->destroy();
 }
開發者ID:spelgrift,項目名稱:imageman,代碼行數:36,代碼來源:Image.php

示例11: thumbnail

 /**
  * @param $file
  * @return string
  */
 public function thumbnail($file)
 {
     $format = '';
     $name = md5((new \DateTime())->format('c'));
     foreach ($this->sizes as $size) {
         $image = new \Imagick($file);
         $imageRatio = $image->getImageWidth() / $image->getImageHeight();
         $width = $size['width'];
         $height = $size['height'];
         $customRation = $width / $height;
         if ($customRation < $imageRatio) {
             $widthThumb = 0;
             $heightThumb = $height;
         } else {
             $widthThumb = $width;
             $heightThumb = 0;
         }
         $image->thumbnailImage($widthThumb, $heightThumb);
         $image->cropImage($width, $height, ($image->getImageWidth() - $width) / 2, ($image->getImageHeight() - $height) / 2);
         $image->setCompressionQuality(100);
         $format = strtolower($image->getImageFormat());
         $pp = $this->cachePath . '/' . $size['name'] . "_{$name}." . $format;
         $image->writeImage($pp);
     }
     return "_{$name}." . $format;
 }
開發者ID:ahonymous,項目名稱:crop-imagick,代碼行數:30,代碼來源:ImagickService.php

示例12: handleSave

 /**
  * @param Asset $asset
  * @return string
  */
 public function handleSave(Asset $asset)
 {
     $newImage = new \Imagick($asset->getUploadedFile()->getRealPath());
     $asset->setHeight($newImage->getImageHeight());
     $asset->setWidth($newImage->getImageWidth());
     /** @var array $requiredImage */
     foreach ($this->requiredImages as $requiredImage) {
         $newImage = new \Imagick($asset->getUploadedFile()->getRealPath());
         $newFilename = pathinfo($asset->getFilename(), PATHINFO_FILENAME) . '-' . $requiredImage['name'] . '.' . pathinfo($asset->getFilename(), PATHINFO_EXTENSION);
         $imageWidth = $newImage->getImageWidth();
         $imageHeight = $newImage->getImageHeight();
         $isLandscapeFormat = $imageWidth > $imageHeight;
         $orientation = $newImage->getImageOrientation();
         $newImage->setCompression(\Imagick::COMPRESSION_JPEG);
         $newImage->setImageCompressionQuality($requiredImage['quality']);
         if ($isLandscapeFormat) {
             $desiredWidth = $requiredImage['long'];
             $newImage->resizeImage($desiredWidth, 0, \Imagick::FILTER_LANCZOS, 1);
             if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) {
                 $newImage->cropImage($desiredWidth, $requiredImage['short'], 0, 0);
             } else {
                 $newImage->resizeImage(0, $requiredImage['short'], \Imagick::FILTER_LANCZOS, 1);
             }
         } else {
             $desiredHeight = $requiredImage['long'];
             $newImage->resizeImage(0, $desiredHeight, \Imagick::FILTER_LANCZOS, 1);
             if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) {
                 $newImage->cropImage($requiredImage['short'], $desiredHeight, 0, 0);
             } else {
                 $newImage->resizeImage($requiredImage['short'], 0, \Imagick::FILTER_LANCZOS, 1);
             }
         }
         /**
          * This unfortunately kills the orientation. Leave EXIF-Info for now.
          *
          * $newImage->stripImage();
          * $newImage->setImageOrientation($orientation);
          */
         $this->assetStorage->uploadFile($newFilename, $newImage);
         $subAsset = new SubAsset();
         $subAsset->setFilename($newFilename);
         $subAsset->setType($requiredImage['name']);
         $subAsset->setHeight($newImage->getImageHeight());
         $subAsset->setWidth($newImage->getImageWidth());
         $asset->addSubAsset($subAsset);
     }
 }
開發者ID:keylightberlin,項目名稱:util,代碼行數:51,代碼來源:ImageAssetHandler.php

示例13: _crop

 /**
  * Crop the image.
  * @param int $width
  * @param int $height
  * @param int $offset_x
  * @param int $offset_y
  */
 protected function _crop($width, $height, $offset_x, $offset_y)
 {
     if ($this->im->cropImage($width, $height, $offset_x, $offset_y)) {
         $this->width = $this->im->getImageWidth();
         $this->height = $this->im->getImageHeight();
         $this->im->setImagePage($this->width, $this->height, 0, 0);
     }
 }
開發者ID:dgan89,項目名稱:yii2-image,代碼行數:15,代碼來源:Imagick.php

示例14: crop

 /**
  * @param int $width
  * @param int $height
  * @param int $offsetX
  * @param int $offsetY
  *
  * @return static
  */
 public function crop($width, $height, $offsetX = 0, $offsetY = 0)
 {
     $this->_image->cropImage($width, $height, $offsetX, $offsetY);
     $this->_image->setImagePage($width, $height, 0, 0);
     $this->_width = $this->_image->getImageWidth();
     $this->_height = $this->_image->getImageHeight();
     return $this;
 }
開發者ID:manaphp,項目名稱:manaphp,代碼行數:16,代碼來源:Imagick.php

示例15: buildFitOut

 protected function buildFitOut($params)
 {
     $newWidth = $params[0];
     $newHeight = $params[1];
     $originalWidth = $this->_image->getImageWidth();
     $originalHeight = $this->_image->getImageHeight();
     $this->_image->setGravity(!empty($params[2]) ? $params[2] : \Imagick::GRAVITY_CENTER);
     $tmpWidth = $newWidth;
     $tmpHeight = $originalHeight * ($newWidth / $originalWidth);
     if ($tmpHeight < $newHeight) {
         $tmpHeight = $newHeight;
         $tmpWidth = $originalWidth * ($newHeight / $originalHeight);
     }
     $this->_image->thumbnailImage($tmpWidth, $tmpHeight);
     $offset = self::detectGravityXY($this->_image->getGravity(), $tmpWidth, $tmpHeight, $params[0], $params[1]);
     $this->_image->cropImage($newWidth, $newHeight, $offset[0], $offset[1]);
 }
開發者ID:solve,項目名稱:graphics,代碼行數:17,代碼來源:IMagickImageAdapter.php


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