Ejemplo n.º 1
1
 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));
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * @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;
 }
Ejemplo n.º 4
0
 /**
  * (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;
 }
Ejemplo n.º 5
0
Archivo: index.php Proyecto: hoogle/ttt
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;
}
 /**
  * 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();
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 /**
  * 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();
 }
Ejemplo n.º 11
0
 /**
  * @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;
 }
Ejemplo n.º 12
0
 /**
  * @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);
     }
 }
Ejemplo n.º 13
0
 /**
  * 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);
     }
 }
Ejemplo n.º 14
0
 /**
  * @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;
 }
Ejemplo n.º 15
0
 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]);
 }
 public function takeScreenshot($jqueryIdentifier = "body")
 {
     $image = new \Imagick();
     $image->readimageblob($this->webDriver->takeScreenshot());
     $coords = $this->getCoordinates($jqueryIdentifier);
     $image->cropImage($coords['width'], $coords['height'], $coords['offset_x'], $coords['offset_y']);
     return $image;
 }
Ejemplo n.º 17
0
 /**
  *
  *    const GRAVITY_NORTHWEST = 1;
  * const GRAVITY_NORTH = 2;
  * const GRAVITY_NORTHEAST = 3;
  * const GRAVITY_WEST = 4;
  * const GRAVITY_CENTER = 5;
  * const GRAVITY_EAST = 6;
  * const GRAVITY_SOUTHWEST = 7;
  * const GRAVITY_SOUTH = 8;
  * const GRAVITY_SOUTHEAST = 9;
  */
 public function renderImage()
 {
     $imagick = new \Imagick(realpath("../imagick/images/Biter_500.jpg"));
     $imagick->setGravity(\Imagick::GRAVITY_SOUTHEAST);
     $imagick->cropImage(400, 300, 0, 0);
     $imagick->setimageformat('png');
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
Ejemplo n.º 18
0
 public function filter($value)
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $cropData = Zend_Json::decode($request->getParam($this->getElementName() . 'CropData'));
     $image = new Imagick($value);
     $image->cropImage($cropData['width'], $cropData['height'], $cropData['x'], $cropData['y']);
     $image->thumbnailImage($this->getResize()[0], $this->getResize()[1]);
     $image->writeImage();
 }
Ejemplo n.º 19
0
 /**
  * @param  $x
  * @param  $y
  * @param  $width
  * @param  $height
  * @return Pimcore_Image_Adapter_Imagick
  */
 public function crop($x, $y, $width, $height)
 {
     $this->resource->cropImage($width, $height, $x, $y);
     $this->resource->setImagePage($width, $height, 0, 0);
     $this->setWidth($width);
     $this->setHeight($height);
     $this->reinitializeImage();
     return $this;
 }
Ejemplo n.º 20
0
 /**
  * @param  $x
  * @param  $y
  * @param  $width
  * @param  $height
  * @return self
  */
 public function crop($x, $y, $width, $height)
 {
     $this->preModify();
     $this->resource->cropImage($width, $height, $x, $y);
     $this->resource->setImagePage($width, $height, 0, 0);
     $this->setWidth($width);
     $this->setHeight($height);
     $this->postModify();
     return $this;
 }
Ejemplo n.º 21
0
 public function crop($top_x, $top_y, $bottom_x, $bottom_y)
 {
     //Crop every other image
     for ($r = 0; $r < count($this->image); $r++) {
         $this->image->nextImage();
         $this->image->cropImage($bottom_x - $top_x, $bottom_y - $top_y, $top_x, $top_y);
     }
     $this->info['width'] = $bottom_x - $top_x;
     $this->info['height'] = $bottom_y - $top_y;
 }
Ejemplo n.º 22
0
 /**
  * Crop the current image.
  *
  * @param integer $x1  x for the top left corner
  * @param integer $y1  y for the top left corner
  * @param integer $x2  x for the bottom right corner of the cropped image.
  * @param integer $y2  y for the bottom right corner of the cropped image.
  */
 public function crop($x1, $y1, $x2, $y2)
 {
     try {
         $result = $this->_imagick->cropImage($x2 - $x1, $y2 - $y1, $x1, $y1);
         $this->_imagick->setImagePage(0, 0, 0, 0);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $this->clearGeometry();
 }
Ejemplo n.º 23
0
Archivo: Crop.php Proyecto: GNURub/daw2
 /**
  * Resize and crop the image so it dimensions matches $targetWidth and $targetHeight
  *
  * @param  int              $targetWidth
  * @param  int              $targetHeight
  * @return boolean|\Imagick
  */
 public function resizeAndCrop($targetWidth, $targetHeight)
 {
     // First get the size that we can use to safely trim down the image without cropping any sides
     $crop = $this->getSafeResizeOffset($this->originalImage, $targetWidth, $targetHeight);
     // Resize the image
     $this->originalImage->resizeImage($crop['width'], $crop['height'], $this->getFilter(), $this->getBlur());
     // Get the offset for cropping the image further
     $offset = $this->getSpecialOffset($this->originalImage, $targetWidth, $targetHeight);
     // Crop the image
     $this->originalImage->cropImage($targetWidth, $targetHeight, $offset['x'], $offset['y']);
     return $this->originalImage;
 }
Ejemplo n.º 24
0
 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::clip()
  */
 public function clip($originX, $originY, $width, $height)
 {
     if ($this->imagick->getImageFormat() == 'GIF') {
         $this->imagick = $this->imagick->coalesceImages();
         do {
             $this->imagick->cropImage($width, $height, $originX, $originY);
             $this->imagick->setImagePage($width, $height, 0, 0);
         } while ($this->imagick->nextImage());
     } else {
         $this->imagick->cropImage($width, $height, $originX, $originY);
     }
 }
Ejemplo n.º 25
0
 public function crop($width, $height, $x = 0, $y = 0)
 {
     if ($width > ($maxwidth = $this->width - $x)) {
         $width = $maxwidth;
     }
     if ($height > ($maxheight = $this->height - $y)) {
         $height = $maxheight;
     }
     $this->image->cropImage($width, $height, $x, $y);
     $this->updateSize($width, $height);
     return $this;
 }
	function thumb($pdffile, $jpegfile, $width, $output = false) {
		list($src_width, $src_height, $src_type, $src_attr) = imgetimagesize($pdffile);
		list($tgt_width, $tgt_height, $tgt_type, $tgt_attr) = setimagesize($pdffile, $width);
		$ii = pathinfo($pdffile);
		
		$input = trim(strtolower(str_replace('.','',$ii['extension'])));
		$output = (!$output ? $input : $output);

		if (class_exists('Imagick')) {
			$im = new Imagick();
			$im->setResolution( 300, 300 ); 
			if ($input == "pdf") {
				$im->readImage($pdffile.'[0]');
				$im->cropImage(($src_width - 60),($src_height - 60),30,30);
			} else {
				$im->readImage($pdffile);
			}
			// $im->setImageColorspace(Imagick::COLORSPACE_SRGB);
			$im->adaptiveResizeImage($tgt_width, $tgt_height, true);
			$im->setImageFormat("jpg");
			//$im->setImageCompressionQuality(100);
			$im->writeImage($jpegfile);
		} else {
			if ($input == "gif") {
				$im = imagecreatefromgif($pdffile);
				$it = imagecreate($tgt_width, $tgt_height);
			} elseif ($input == "png") {
				$im = imagecreatefrompng($pdffile);
				$it = imagecreatetruecolor($tgt_width, $tgt_height);
				imagealphablending($it, false);
 				imagesavealpha($it,true);
 				$transparent = imagecolorallocatealpha($it, 255, 255, 255, 127);
	 			imagefilledrectangle($it, 0, 0, $tgt_width, $tgt_height, $transparent);
			} else {
				$im = imagecreatefromjpeg($pdffile);
				$it = imagecreatetruecolor($tgt_width, $tgt_height);
			}
			
			imagecopyresampled($it, $im, 0, 0, 0, 0, $tgt_width, $tgt_height, $src_width, $src_height);
			
			if ($output == "gif") {
				imagegif($it, $jpegfile);
			} elseif ($output == "png") {
				imagepng($it, $jpegfile);
			} else {
				imagejpeg($it, $jpegfile);
			}
		}
	}
Ejemplo n.º 27
0
 /**
  * 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);
     }
 }
 /**
  * Crops the image
  *
  * @param integer $width Cropped image width
  * @param integer $height Cropped image height
  * @param integer $x X-coordinate to crop at
  * @param integer $y Y-coordinate to crop at
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function crop($width, $height, $x = 0, $y = 0)
 {
     // Sanity check
     if (!$this->intersects($width, $height, $x, $y)) {
         return PEAR::raiseError('Nothing to crop', IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
     }
     try {
         $this->imagick->cropImage($width, $height, $x, $y);
     } catch (ImagickException $e) {
         return $this->raiseError('Could not crop image', IMAGE_TRANSFORM_ERROR_FAILED);
     }
     // I think that setting img_x/y is wrong, but scaleByLength() & friends
     // mess up the aspect after a crop otherwise.
     $this->new_x = $width;
     $this->new_y = $height;
     return true;
 }
Ejemplo n.º 29
0
 protected function _crop($newFile, $resizeWidth, $resizeHeight, $newWidth, $newHeight, $cropX, $cropY, $resize = true)
 {
     $imagick = new Imagick();
     $imagick->readImage($this->_file);
     if ($resize) {
         /**
          * Resize
          */
         $imagick->resizeImage($resizeWidth, $resizeHeight, Imagick::FILTER_LANCZOS, 1);
     }
     /**
      * Crop
      */
     $imagick->cropImage($newWidth, $newHeight, $cropX, $cropY);
     $imagick->writeImage($newFile);
     $imagick->clear();
     $imagick->destroy();
 }
Ejemplo n.º 30
0
 public function crop($width, $height, $x = 0, $y = 0)
 {
     if ($width > ($maxwidth = $this->width - $x)) {
         $width = $maxwidth;
     }
     if ($height > ($maxheight = $this->height - $y)) {
         $height = $maxheight;
     }
     if ($this->multiframe()) {
         $this->image = $this->image->coalesceImages();
         foreach ($this->image as $frame) {
             $frame->cropImage($width, $height, $x, $y);
             $frame->setImagePage($width, $height, 0, 0);
         }
     } else {
         $this->image->cropImage($width, $height, $x, $y);
     }
     $this->update_size($width, $height);
     return $this;
 }