Example #1
1
 function mkbilder()
 {
     $this->err->write('mkbilder', 'IN');
     if (!class_exists("Imagick")) {
         $this->err->out("Imagick-Extention nicht installiert", true);
         return false;
     }
     $handle = new Imagick();
     if (!$handle->readImage("./tmp/tmp.file_org")) {
         return false;
     }
     $d = $handle->getImageGeometry();
     if ($d["width"] < $d["height"]) {
         $faktor = $d["height"] / $d["width"];
     } else {
         $faktor = $d["width"] / $d["height"];
     }
     $thumbheight = floor($this->thumbwidth * $faktor);
     $handle->thumbnailImage($this->thumbwidth, $thumbheight);
     $rc = $handle->writeImage("./tmp/tmp.file_thumb");
     $handle->readImage("./tmp/tmp.file_org");
     $popupheight = floor($this->popupwidth * $faktor);
     $handle->thumbnailImage($this->popupwidth, $popupheight);
     $rc = $handle->writeImage("./tmp/tmp.file_popup");
     $handle->readImage("./tmp/tmp.file_org");
     $infoheight = floor($this->infowidth * $faktor);
     $handle->thumbnailImage($this->infowidth, $infoheight);
     $rc = $handle->writeImage("./tmp/tmp.file_info");
     return $rc;
 }
Example #2
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));
 }
Example #3
1
 /**
  * Generates a new jpg image with new sizes from an already existing file.
  * (This will also work on raw files, but it will be exceptionally
  * slower than extracting the preview).
  *
  * @param  	string	$sourceFilePath	the path to the original file
  * @param  	string	$targetFilePath	the path to the target file
  * @param  	int		$width			the max width
  * @param  	int		$height			the max height of the image
  * @param  	int		$quality		the quality of the new image (0-100)
  *
  * @throws \InvalidArgumentException
  *
  * @return void.
  */
 public static function generateImage($sourceFilePath, $targetFilePath, $width, $height, $quality = 60)
 {
     if (!self::checkFile($sourceFilePath)) {
         throw new \InvalidArgumentException('Incorrect filepath given');
     }
     $im = new \Imagick($sourceFilePath);
     $im->setImageFormat('jpg');
     $im->setImageCompressionQuality($quality);
     $im->stripImage();
     $im->thumbnailImage($width, $height, true);
     $im->writeImage($targetFilePath);
     $im->clear();
     $im->destroy();
 }
Example #4
1
function multiply($firstPicture, $twoPicture, $x, $y)
{
    $img = new Imagick($firstPicture);
    $img->thumbnailImage(140, 140);
    $shadow = $img->clone();
    $shadow->setImageBackgroundColor(new ImagickPixel('black'));
    //color shadow
    $shadow->shadowImage(80, 3, 5, 5);
    //create shadow
    $shadow->compositeImage($img, Imagick::COMPOSITE_OVER, 0, 0);
    header("Content-Type: image/jpeg");
    $img2 = new Imagick($twoPicture);
    $img2->compositeImage($shadow, $shadow->getImageCompose(), $x, $y);
    echo $img2;
}
 /**
  * @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;
 }
 /**
  * @param ImageInterface $image
  * @param Size $size
  * @param bool $allow_enlarge
  */
 public function resize(ImageInterface $image, Size $sizeDest, $allow_enlarge = false)
 {
     $widthDest = 0;
     $heightDest = 0;
     $imagick = new \Imagick($image->getPath());
     $srcWidth = $image->getImageSize()->getHeight();
     $srcHeight = $image->getImageSize()->getWidth();
     if ($srcWidth > $srcHeight) {
         $widthDest = $sizeDest->getWidth();
     } else {
         if ($srcHeight > $srcWidth) {
             $heightDest = $sizeDest->getHeight();
         } else {
             $widthDest = $sizeDest->getWidth();
             $heightDest = $sizeDest->getHeight();
         }
     }
     $imagick->thumbnailImage($widthDest, $heightDest);
     $addToName = "_resized_" . $imagick->getImageWidth() . "x" . $imagick->getImageHeight();
     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);
 }
Example #7
0
 /**
  * Creates a thumbnail with imagick.
  *
  * @param  File    $fileObject           FileObject to add properties
  * @param  string  $httpPathToMediaDir   Http path to file
  * @param  string  $pathToMediaDirectory Local path to file
  * @param  string  $fileName             Name of the image
  * @param  string  $fileExtension        Fileextension
  * @param  integer $width                Width of thumbnail, if omitted, size will be proportional to height
  * @param  integer $height               Height of thumbnail, if omitted, size will be proportional to width
  *
  * @throws ThumbnailCreationFailedException              If imagick is not supported
  * @throws InvalidArgumentException      If both, height and width are omitted or file format is not supported
  */
 private static function createThumbnailWithImagick(File &$fileObject, $httpPathToMediaDir, $pathToMediaDirectory, $fileName, $fileExtension, $width = null, $height = null)
 {
     if (!extension_loaded('imagick')) {
         throw new ExtensionNotLoadedException('Imagick is not loaded on this system');
     }
     if ($width === null && $height === null) {
         throw new InvalidArgumentException('Either width or height must be provided');
     }
     // create thumbnails with imagick
     $imagick = new \Imagick();
     if (!in_array($fileExtension, $imagick->queryFormats("*"))) {
         throw new ThumbnailCreationFailedException('No thumbnail could be created for the file format');
     }
     // read image into imagick
     $imagick->readImage(sprintf('%s/%s.%s', $pathToMediaDirectory, $fileName, $fileExtension));
     // set size
     $imagick->thumbnailImage($width, $height);
     // null values allowed
     // write image
     $imagick->writeImage(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setThumbnailLink(sprintf('%s/%sx%s-thumbnail-%s.%s', $httpPathToMediaDir, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setLocalThumbnailPath(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     // free up associated resources
     $imagick->destroy();
 }
 /**
  * @param Thumbnail $thumbnail
  * @return void
  * @throws Exception\NoThumbnailAvailableException
  */
 public function refresh(Thumbnail $thumbnail)
 {
     try {
         $filenameWithoutExtension = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME);
         $temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy();
         $documentFile = sprintf(in_array($thumbnail->getOriginalAsset()->getResource()->getFileExtension(), $this->getOption('paginableDocuments')) ? '%s[0]' : '%s', $temporaryLocalCopyFilename);
         $width = $thumbnail->getConfigurationValue('width') ?: $thumbnail->getConfigurationValue('maximumWidth');
         $height = $thumbnail->getConfigurationValue('height') ?: $thumbnail->getConfigurationValue('maximumHeight');
         $im = new \Imagick();
         $im->setResolution($this->getOption('resolution'), $this->getOption('resolution'));
         $im->readImage($documentFile);
         $im->setImageFormat('png');
         $im->setImageBackgroundColor('white');
         $im->setImageCompose(\Imagick::COMPOSITE_OVER);
         $im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_RESET);
         $im->thumbnailImage($width, $height, true);
         $im->flattenImages();
         // Replace flattenImages in imagick 3.3.0
         // @see https://pecl.php.net/package/imagick/3.3.0RC2
         // $im->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);
         $resource = $this->resourceManager->importResourceFromContent($im->getImageBlob(), $filenameWithoutExtension . '.png');
         $im->destroy();
         $thumbnail->setResource($resource);
         $thumbnail->setWidth($width);
         $thumbnail->setHeight($height);
     } catch (\Exception $exception) {
         $filename = $thumbnail->getOriginalAsset()->getResource()->getFilename();
         $sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1();
         $message = sprintf('Unable to generate thumbnail for the given document (filename: %s, SHA1: %s)', $filename, $sha1);
         throw new Exception\NoThumbnailAvailableException($message, 1433109652, $exception);
     }
 }
Example #9
0
 protected function save($path)
 {
     $pathinfo = pathinfo($path);
     if (!file_exists($pathinfo['dirname'])) {
         mkdir($pathinfo['dirname'], 0777, true);
     }
     try {
         $image = new \Imagick($this->source);
         $image->thumbnailImage($this->width, $this->height, true);
         if ($this->color) {
             $thumb = $image;
             $image = new \Imagick();
             $image->newImage($this->width, $this->height, $this->color, $pathinfo['extension']);
             $size = $thumb->getImageGeometry();
             $x = ($this->width - $size['width']) / 2;
             $y = ($this->height - $size['height']) / 2;
             $image->compositeImage($thumb, \imagick::COMPOSITE_OVER, $x, $y);
             $thumb->destroy();
         }
         $image->writeImage($path);
         $image->destroy();
     } catch (\Exception $e) {
     }
     return $this;
 }
Example #10
0
 function imagick_thumbnail($image, $timage, $ext, $thumbnail_name, $imginfo)
 {
     try {
         $imagick = new Imagick();
         $fullpath = "./" . $this->thumbnail_path . "/" . $timage[0] . "/" . $thumbnail_name;
         if ($ext == "gif") {
             $imagick->readImage($image . '[0]');
         } else {
             $imagick->readImage($image);
         }
         $info = $imagick->getImageGeometry();
         $this->info[0] = $info['width'];
         $this->info[1] = $info['height'];
         $imagick->thumbnailImage($this->dimension, $this->dimension, true);
         if ($ext == "png" || $ext == "gif") {
             $white = new Imagick();
             $white->newImage($this->dimension, $this->dimension, "white");
             $white->compositeimage($image, Imagick::COMPOSITE_OVER, 0, 0);
             $white->writeImage($fullpath);
             $white->clear();
         } else {
             $imagick->writeImage($fullpath);
         }
         $imagick->clear();
     } catch (Exception $e) {
         echo "Unable to load image." . $e->getMessage();
         return false;
     }
     return true;
 }
Example #11
0
function upload_image($arr_image, $location, $compression = null, $width = 245, $height = 170)
{
    $image_location = "";
    $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG", "JPEG", "GIF", "PNG", "pdf", "PDF");
    $temp = explode(".", $arr_image["file"]["name"]);
    $extension = end($temp);
    if (($arr_image["file"]["type"] == "image/gif" || $arr_image["file"]["type"] == "image/jpeg" || $arr_image["file"]["type"] == "image/jpg" || $arr_image["file"]["type"] == "image/pjpeg" || $arr_image["file"]["type"] == "image/x-png" || $arr_image["file"]["type"] == "image/png") && $arr_image["file"]["size"] < 1024 * 1000 * 10 && in_array($extension, $allowedExts)) {
        if ($arr_image["file"]["error"] > 0) {
            echo "Return Code: " . $arr_image["file"]["error"] . "<br>";
        } else {
            $compression_type = Imagick::COMPRESSION_JPEG;
            $image_location = $location . "." . $extension;
            if (move_uploaded_file($arr_image["file"]["tmp_name"], $image_location)) {
                //echo "Image Uploaded to : ".$image_location;
            } else {
                //echo "Image not uploaded";
            }
            if (is_null($compression)) {
                $im = new Imagick($image_location);
                $im->setImageFormat('jpg');
                $im->setImageCompression($compression_type);
                $im->setImageCompressionQuality(95);
                $im->stripImage();
                $im->thumbnailImage($width, $height);
                $image_location = $location . ".jpg";
                $im->writeImage($image_location);
            }
        }
    }
    return $image_location;
}
Example #12
0
function resize_image($file, $out_file, $width, $height = 0)
{
    if (extension_loaded('imagick')) {
        $img = new Imagick($file);
        $img->thumbnailImage($width, $height);
        $img->writeImage($out_file);
    }
    if (extension_loaded('gd')) {
        $ext = image_type($file);
        if ($ext == 'jpg' || $ext == 'jpeg') {
            $src_img = imagecreatefromjpeg($file);
        } else {
            $src_img = imagecreatefrompng($file);
        }
        $old_x = imageSX($src_img);
        $old_y = imageSY($src_img);
        if ($height == 0) {
            $height = $old_y * $width / $old_x;
        }
        $dst_img = ImageCreateTrueColor($width, $height);
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y);
        $ext = image_type($out_file);
        if ($ext == 'jpg' || $ext == 'jpeg') {
            imagejpeg($dst_img, $out_file);
        } else {
            imagepng($dst_img, $out_file);
        }
        imagedestroy($dst_img);
        imagedestroy($src_img);
    }
    return null;
}
 function _resize_image($image_path, $max_width = 100, $max_height = 100)
 {
     $imagick = new \Imagick(realpath($image_path));
     $imagick->thumbnailImage($max_width, $max_height, true);
     $blob = $imagick->getImageBlob();
     $imagick->clear();
     return $blob;
 }
Example #14
0
    /**
     * Homothetic resizement
     *
     * @param \Imagick image
     * @param integer $maxwidth
     * @param integer $maxheight
     */
    public function homothetic(\Imagick $image, $width, $height)
    {
        list($width, $height) = $this->scaleImage($image->getImageWidth(), $image->getImageHeight(), $width, $height);

        $image->thumbnailImage($width, $height);

        $image->unsharpMaskImage(0 , 0.5 , 1 , 0.05);
    }
Example #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]);
 }
Example #16
0
function thumbnailImage($imagePath)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->setbackgroundcolor('rgb(64, 64, 64)');
    $imagick->thumbnailImage(300, 300, true, true);
    //header("Content-Type: image/jpg");
    return $imagick->getImageBlob();
}
Example #17
0
 public function resize($src_file, $target_file, $width, $height, $type, $new_width, $new_height)
 {
     $thumb = new Imagick($src_file);
     $thumb->thumbnailImage($new_width, $new_height);
     $thumb->writeImage($target_file);
     $thumb->clear();
     $thumb->destroy();
 }
Example #18
0
 public function newThumbnail($docId)
 {
     $documentObj = new Document_Model($docId);
     $fileExt = $documentObj->getExt();
     //The obfuscated file name, stored in the location column
     $docName = $documentObj->getLocation();
     //The docName without the file extention
     $baseName = $documentObj->getBaseName();
     switch ($fileExt) {
         case 'pdf':
             $url = base_url() . $this->config->item('dataDir') . $docName;
             $newImage = $this->config->item('dataDir') . 'thumbnails/' . $baseName . '.jpg';
             if (extension_loaded('imagick')) {
                 //create a thumbnail from the screenshot
                 $thumb = new Imagick($url . [0]);
                 $thumb->thumbnailImage(400, 0);
                 $thumb->writeImage($newImage);
                 $msg = array('status' => 'success', 'msg' => 'Thumbnail was successfully created.');
                 echo json_encode($msg);
             } else {
                 $msg = array('status' => 'error', 'msg' => 'You must have ImageMagick installed to convert a pdf to thumbnail image.');
                 echo json_encode($msg);
             }
             break;
         case 'html':
         case 'php':
         case 'htm':
             //create PDF from HTML
             $html = $this->load->file(FCPATH . $this->config->item('dataDir') . $docName, true);
             //create thumbnail from HTML
             $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip');
             $newImage = $this->config->item('dataDir') . 'thumbnails/' . $baseName . '.jpg';
             $this->image->generateFromHtml($html, $newImage, $options, true);
             $msg = array('status' => 'success', 'msg' => 'Successfully created a thumbnail of your file.');
             echo json_encode($msg);
             break;
         case 'png':
         case 'jpg':
             $config['source_image'] = $this->config->item('dataDir') . $docName;
             $config['new_image'] = $this->config->item('dataDir') . 'thumbnails/' . $docName;
             $config['maintain_ratio'] = true;
             $config['height'] = 200;
             $this->load->library('image_lib', $config);
             if (!$this->image_lib->resize()) {
                 $msg = array('status' => 'error', 'msg' => 'There was an error trying to resize the image.');
                 echo json_encode($msg);
             } else {
                 $msg = array('status' => 'success', 'msg' => 'Successfully created a thumbnail of your image.');
                 echo json_encode($msg);
             }
             break;
         default:
             $msg = array('status' => 'error', 'msg' => 'This filetype is currently not supported for making thumbnails.');
             echo json_encode($msg);
             break;
     }
 }
Example #19
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Image\ManipulatorInterface::resize()
  */
 public function resize(BoxInterface $size)
 {
     try {
         $this->imagick->thumbnailImage($size->getWidth(), $size->getHeight());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Resize operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Example #20
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();
 }
Example #21
0
 /**
  * @return \ImageStorage\Image\Structure\Image
  * @throws \Exception
  */
 private function _watermark_rand()
 {
     if (false === file_exists($this->_watermarkRand->fileName)) {
         throw new \Exception('File ' . $this->_watermarkRand->fileName . ' not exist!');
     }
     $config = $this->_watermarkRand;
     if (false === class_exists('\\Imagick')) {
         return $this->_imageStruct;
     }
     //prepare source in Imagick
     $source = new \Imagick();
     $source->readImageBlob($this->getJpgBlobFromGd($this->_imageStruct->image));
     //prepare watermark
     $watermark = new \Imagick($this->_watermarkRand->fileName);
     $maxWatermarkSize = $source->getImageWidth() * $config->getSize();
     if ($maxWatermarkSize < $config->getMinSize()) {
         $maxWatermarkSize = $config->getMinSize();
     }
     $watermark->thumbnailImage($maxWatermarkSize, $maxWatermarkSize);
     //cache image size
     $imageWidth = $source->getImageWidth();
     $imageHeight = $source->getImageHeight();
     //set max watermarks
     $maxCols = $imageWidth / $config->getMinSize() / 2;
     if ($maxCols < $config->getCols()) {
         $config->setCols(ceil($maxCols));
     }
     $maxRows = $imageHeight / $config->getMinSize() / 2;
     if ($maxRows < $config->getRows()) {
         $config->setRows(ceil($maxRows));
     }
     //step width
     $stepWidth = $imageWidth / $config->getCols();
     $stepHeight = $imageHeight / $config->getRows();
     //put images
     for ($row = 0; $row < $config->getRows(); $row++) {
         for ($col = 0; $col < $config->getCols(); $col++) {
             $x = rand($col * $stepWidth, ($col + 1) * $stepWidth);
             $y = rand($row * $stepHeight, ($row + 1) * $stepHeight);
             //make sure that watermark is in image bound
             if ($x + $maxWatermarkSize > $imageWidth) {
                 $x = $imageWidth - $maxWatermarkSize;
             }
             if ($y + $maxWatermarkSize > $imageHeight) {
                 $y = $imageHeight - $maxWatermarkSize;
             }
             //put watermark to image
             $source->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $x, $y);
         }
     }
     $source->setImageFormat("jpeg");
     $this->_imageStruct->image = imagecreatefromstring($source->getImageBlob());
     return $this->_imageStruct;
 }
Example #22
0
function resize_image($file, $w, $h, $crop = FALSE)
{
    // @param file, width, height, crop
    // Resize an image using Imagick
    $img = new Imagick($file);
    if ($crop) {
        $img->cropThumbnailImage($w, $h);
    } else {
        $img->thumbnailImage($w, $h, TRUE);
    }
    return $img;
}
Example #23
0
 private function createThumbnails()
 {
     $thumb = new Imagick($this->path);
     foreach ($this->widths as $append => $width) {
         $name = $this->names[$append];
         if ($this->size[0] > $width) {
             $height = $thumb->getImageHeight() / $thumb->getImageWidth() * $width;
             $thumb->thumbnailImage($width, $height, true);
         }
         $thumb->writeImage($name);
     }
 }
Example #24
0
 function makeThumbnailtoFile($destFile)
 {
     $returnVal = false;
     if (!$this->isWorking()) {
         return false;
     }
     $image = new Imagick($this->sourceFile);
     $image->setCompressionQuality($this->thumbQuality);
     $image->thumbnailImage($this->thumbWidth, $this->thumbHeight);
     $returnVal = $image->writeImage($destFile);
     unset($image);
     return $returnVal;
 }
Example #25
0
 /**
  * Resize current image.
  *
  * @see Horde_Image_im::resize()
  *
  * @return void
  */
 public function resize($width, $height, $ratio = true, $keepProfile = false)
 {
     try {
         if ($keepProfile) {
             $this->_imagick->resizeImage($width, $height, $ratio);
         } else {
             $this->_imagick->thumbnailImage($width, $height, $ratio);
         }
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $this->clearGeometry();
 }
function perspective($firstPicture, $twoPicture, $pointTLX, $pointTLY, $pointBLX, $pointBLY, $pointTRX, $pointTRY, $pointBRX, $pointBRY)
{
    $imagick = new \Imagick(realpath($firstPicture));
    $points = array(array('x' => $pointTLX, 'y' => $pointTLY), array('x' => $pointBLX, 'y' => $pointBLY), array('x' => $pointTRX, 'y' => $pointTRY), array('x' => $pointBRX, 'y' => $pointBRY));
    $geometry = $imagick->getImageGeometry();
    $controlPoints = array(0, 0, $points[0]['x'], $points[0]['y'], 0, $geometry['height'], $points[1]['x'], $points[1]['y'], $geometry['width'], 0, $points[2]['x'], $points[2]['y'], $geometry['width'], $geometry['height'], $points[3]['x'], $points[3]['y']);
    $imagick->distortImage(Imagick::DISTORTION_AFFINE, $controlPoints, true);
    header("Content-Type: image/jpg");
    $img2 = new Imagick($twoPicture);
    $imagick->thumbnailImage(140, 140);
    //$img2->compositeImage($imagick, $imagick->getImageCompose(), 155, 290);
    $img2->compositeImage($imagick, $imagick->getImageCompose(), $pointTLX, $pointTRY);
    echo $img2;
}
Example #27
0
function createIcon($file)
{
    // @todo: Add support for others methods.
    if (class_exists("Imagick")) {
        $img = new Imagick();
        $img->readImageBlob(file_get_contents($file));
        $img->thumbnailImage(100, 100, true);
        return base64_encode($img);
    } elseif (extension_loaded('gd')) {
        return createIconGD($file);
    } else {
        return giftThumbnail();
    }
}
 /**
  * Resizes the source image.
  * 
  * @param array $dimensions
  * @return true if image resizing was successful
  */
 public function resize(array $dimensions)
 {
     if (!$this->source_resource instanceof Imagick || !$this->destination instanceof sfFilebasePluginImage) {
         throw new sfFilebasePluginException('You must set a source and a destination image to resize.');
     }
     $image_data = $this->gfxEditor->getScaledImageData($this->source, $dimensions);
     $width = $image_data['orig_width'];
     $height = $image_data['orig_height'];
     $new_width = $image_data['new_width'];
     $new_height = $image_data['new_height'];
     $mime = $image_data['mime'];
     $this->destination_resource->thumbnailImage($new_width, $new_height);
     return true;
 }
Example #29
0
 /**
  * Generate a derivative image with Imagick.
  */
 public function createImage($sourcePath, $destPath, $type, $sizeConstraint, $mimeType)
 {
     $page = (int) $this->getOption('page', 0);
     try {
         $imagick = new Imagick($sourcePath . '[' . $page . ']');
     } catch (ImagickException $e) {
         _log("Imagick failed to open the file. Details:\n{$e}", Zend_Log::ERR);
         return false;
     }
     $imagick->setBackgroundColor('white');
     $imagick->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
     if ($type != 'square_thumbnail') {
         $imagick->thumbnailImage($sizeConstraint, $sizeConstraint, true);
     } else {
         // We could use cropThumbnailImage here but it lacks support for
         // the gravity setting
         $origX = $imagick->getImageWidth();
         $origY = $imagick->getImageHeight();
         if ($origX < $origY) {
             $newX = $sizeConstraint;
             $newY = $origY * ($sizeConstraint / $origX);
             $offsetX = 0;
             $offsetY = $this->_getCropOffsetY($newY, $sizeConstraint);
         } else {
             $newY = $sizeConstraint;
             $newX = $origX * ($sizeConstraint / $origY);
             $offsetY = 0;
             $offsetX = $this->_getCropOffsetX($newX, $sizeConstraint);
         }
         $imagick->thumbnailImage($newX, $newY);
         $imagick->cropImage($sizeConstraint, $sizeConstraint, $offsetX, $offsetY);
         $imagick->setImagePage($sizeConstraint, $sizeConstraint, 0, 0);
     }
     $imagick->writeImage($destPath);
     $imagick->clear();
     return true;
 }
Example #30
0
 /**
  * 图片临时存储
  *
  * @param unknown_type $uuid            
  */
 public function printUploadArticleImageTemp()
 {
     $this->load->library('form');
     $this->load->helper('form/image');
     $postData = $this->form->check(imageform_get_upload_attachment());
     $errors = $this->form->getLastMessage();
     if (false == empty($errors)) {
         response_to_json(4, $errors);
         exit;
     }
     $check = $this->config->item('check');
     $extName = strtolower(substr($postData['Filedata']['value'][0]['name'], strrpos($postData['Filedata']['value'][0]['name'], '.') + 1));
     $upload = $this->config->item('upload');
     $baseDir = $upload['tempDir'] . '/article/';
     if (false == is_dir($baseDir)) {
         @mkdir($baseDir);
     }
     $titag = time();
     $finalFullFileName = $baseDir . $titag . '.' . $extName;
     @move_uploaded_file($postData['Filedata']['value'][0]['tmp_name'], $finalFullFileName);
     // 生成缩略图
     list($width, $height, $type, $attr) = getimagesize($finalFullFileName);
     $maxSideLength = $width > $height ? $width : $height;
     // 读取图片缩放配置
     $productImageZoom = $this->config->item('articleImageZoom');
     $piSize = array();
     foreach ($productImageZoom as $k => $sideLength) {
         $img = new Imagick($finalFullFileName);
         $zoomFile = $baseDir . $titag . '-' . $k . '.' . $extName;
         if ($sideLength > $maxSideLength) {
             copy($finalFullFileName, $zoomFile);
         } else {
             if ($width > $height) {
                 $newWidth = $sideLength;
                 $newHeight = intval($sideLength * $height / $width);
             } else {
                 $newHeight = $sideLength;
                 $newWidth = intval($sideLength * $width / $height);
             }
             $img->thumbnailImage($newWidth, $newHeight);
             $img->writeImage($zoomFile);
             unset($img);
         }
         $size = getimagesize($zoomFile);
     }
     $zoomFile_small = $baseDir . $titag . '-small.' . $extName;
     $result = array('small' => $zoomFile_small, 'original' => $finalFullFileName);
     response_to_json(0, 'ok', $result);
 }