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


PHP Imagick::thumbnailImage方法代碼示例

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


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

示例1: mkbilder

 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;
 }
開發者ID:vanloswang,項目名稱:kivitendo-crm,代碼行數:30,代碼來源:PictureXTC.php

示例2: 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

示例3: generateImage

 /**
  * 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();
 }
開發者ID:tal512,項目名稱:gphoto-webui,代碼行數:29,代碼來源:CameraRaw.php

示例4: multiply

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;
}
開發者ID:Arxemond777,項目名稱:Multiply,代碼行數:15,代碼來源:indexMultiply.php

示例5: 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

示例6: resize

 /**
  * @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);
 }
開發者ID:vzaramel,項目名稱:Arkivar,代碼行數:32,代碼來源:ImagickImageManipulator.php

示例7: createThumbnailWithImagick

 /**
  * 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();
 }
開發者ID:rmatil,項目名稱:angular-cms,代碼行數:39,代碼來源:ThumbnailHandler.php

示例8: refresh

 /**
  * @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);
     }
 }
開發者ID:mgoldbeck,項目名稱:neos-development-collection,代碼行數:37,代碼來源:DocumentThumbnailGenerator.php

示例9: save

 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;
 }
開發者ID:disdain,項目名稱:thumb,代碼行數:25,代碼來源:Thumb.php

示例10: Imagick

 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;
 }
開發者ID:logtcn,項目名稱:gelbooru-fork,代碼行數:30,代碼來源:image.class.php

示例11: upload_image

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;
}
開發者ID:dturakhia,項目名稱:ryametrostar,代碼行數:31,代碼來源:upload.php

示例12: resize_image

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;
}
開發者ID:zhaoshengloveqingqing,項目名稱:Wechat,代碼行數:32,代碼來源:qrhelper.php

示例13:

 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;
 }
開發者ID:maxmumford,項目名稱:j9-photo-manager,代碼行數:8,代碼來源:PhotoManager.php

示例14: homothetic

    /**
     * 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);
    }
開發者ID:nresni,項目名稱:ImageResizerBundle,代碼行數:15,代碼來源:Processor.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::thumbnailImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。