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


PHP Imagick::readImage方法代碼示例

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


在下文中一共展示了Imagick::readImage方法的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: 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

示例3: getThumbnail

 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $mimetype = $fileview->getMimeType($path);
     $path = \OC_Helper::mimetypeIcon($mimetype);
     $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
     $svgPath = substr_replace($path, 'svg', -3);
     if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
         // http://www.php.net/manual/de/imagick.setresolution.php#85284
         $svg = new \Imagick();
         $svg->readImage($svgPath);
         $res = $svg->getImageResolution();
         $x_ratio = $res['x'] / $svg->getImageWidth();
         $y_ratio = $res['y'] / $svg->getImageHeight();
         $svg->removeImage();
         $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
         $svg->setBackgroundColor(new \ImagickPixel('transparent'));
         $svg->readImage($svgPath);
         $svg->setImageFormat('png32');
         $image = new \OC_Image();
         $image->loadFromData($svg);
     } else {
         $image = new \OC_Image($path);
     }
     return $image;
 }
開發者ID:olucao,項目名稱:owncloud-core,代碼行數:25,代碼來源:unknown.php

示例4: __construct

 public function __construct($file)
 {
     if (!self::$checked) {
         self::check();
     }
     parent::__construct($file);
     $this->im = new Imagick();
     $this->im->readImage($file);
 }
開發者ID:navi8602,項目名稱:wa-shop-ppg,代碼行數:9,代碼來源:waImageImagick.class.php

示例5: loadFile

 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     try {
         $this->imagick->clear();
         $this->imagick->readImage($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $this->readImageDimensions();
 }
開發者ID:nick-strohm,項目名稱:WCF,代碼行數:13,代碼來源:ImagickImageAdapter.class.php

示例6: loadFile

 /**
  * @see	wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     try {
         $this->imagick->readImage($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $this->height = $this->imagick->getImageHeight();
     $this->width = $this->imagick->getImageWidth();
 }
開發者ID:ZerGabriel,項目名稱:WCF,代碼行數:13,代碼來源:ImagickImageAdapter.class.php

示例7: __construct

 /**
  * Open the image.
  * @param string $filename
  * @param boolean $throwErrors
  * @throws InvalidParamException
  * @throws \ErrorException
  */
 public function __construct($filename, $throwErrors = true)
 {
     static $isLoaded;
     if (!isset($isLoaded)) {
         $isLoaded = self::isLoaded();
     }
     parent::__construct($filename, $throwErrors);
     $this->im = new \Imagick();
     $this->im->readImage($this->filename);
     if (!$this->im->getImageAlphaChannel()) {
         $this->im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_SET);
     }
 }
開發者ID:dgan89,項目名稱:yii2-image,代碼行數:20,代碼來源:Imagick.php

示例8: load

 function load($file_name, $type = '')
 {
     $this->destroyImage();
     $imginfo = @getimagesize($file_name);
     if (!$imginfo) {
         throw new lmbFileNotFoundException($file_name);
     }
     $this->img = new Imagick();
     $this->img->readImage($file_name);
     if (!$this->img instanceof Imagick) {
         throw new lmbImageCreateFailedException($file_name);
     }
     $this->img_type = $this->img->getImageFormat();
 }
開發者ID:snowjobgit,項目名稱:limb,代碼行數:14,代碼來源:lmbImImageContainer.class.php

示例9: apply

 /**
  * {@inheritDoc}
  */
 public function apply($absolutePath)
 {
     $info = pathinfo($absolutePath);
     if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf')) {
         // If it doesn't exists, extract the first page of the PDF
         if (!file_exists("{$absolutePath}.png")) {
             $this->imagick->readImage($absolutePath . '[0]');
             $this->imagick->setImageFormat('png');
             $this->imagick->writeImage("{$absolutePath}.png");
             $this->imagick->clear();
         }
         $absolutePath .= '.png';
     }
     return $absolutePath;
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:18,代碼來源:PdfTransformer.php

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

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

示例12: _pdfPageToImage

 protected function _pdfPageToImage($input, $page)
 {
     $path = $input . '[' . $page . ']';
     $image = new \Imagick();
     $image->readImage($path);
     return $image;
 }
開發者ID:fooman,項目名稱:tcpdf,代碼行數:7,代碼來源:Common.php

示例13: addWatermark

 public function addWatermark($image_path)
 {
     try {
         // Open the original image
         $image = new \Imagick();
         $is_success = $image->readImage($image_path);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $watermark = new \Imagick();
         $is_success = $watermark->readImage($this->_WATERMARK_IMAGE_PATH);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $image_width = $image->getImageWidth();
         $image_height = $image->getImageHeight();
         $watermark_width = $watermark->getImageWidth();
         $watermark_height = $watermark->getImageHeight();
         $watermark_pos_x = $image_width - $watermark_width - 20;
         $watermark_pos_y = 20;
         // Overlay the watermark on the original image
         $is_success = $image->compositeImage($watermark, \imagick::COMPOSITE_OVER, $watermark_pos_x, $watermark_pos_y);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot save image after watermarked");
         }
         //Write the image
         $image->writeImage($image_path);
     } catch (ImagickException $e) {
         error_log($e->getMessage());
         throw new WatermarkException($e->getMessage(), $e->getCode(), $e);
     }
 }
開發者ID:viggi2004,項目名稱:datacollector-backend,代碼行數:32,代碼來源:Watermark.php

示例14: readFile

 /**
  * @param string      $path
  * @param null|string $name
  *
  * @throws ProcessorException
  *
  * @returns $this
  */
 public function readFile($path, $name = null)
 {
     if (true !== is_readable($path)) {
         throw new ProcessorException('File path is not readable: %s', null, null, (string) $path);
     }
     if (null === $name || strlen($name) === 0) {
         $name = pathinfo($path, PATHINFO_FILENAME);
     }
     $this->initialize(true);
     try {
         $this->im->readImage($path);
     } catch (\Exception $e) {
         throw new ProcessorException('Could not read image %s from path %s: %s', null, $e, (string) $name, (string) $path, (string) $e->getMessage());
     }
     return $this;
 }
開發者ID:scr-be,項目名稱:teavee-image-magic-bundle,代碼行數:24,代碼來源:ImageMagickProcessor.php

示例15: resize

 /**
  * @param  $width
  * @param  $height
  * @return self
  */
 public function resize($width, $height)
 {
     $this->preModify();
     // this is the check for vector formats because they need to have a resolution set
     // this does only work if "resize" is the first step in the image-pipeline
     if ($this->isVectorGraphic()) {
         // the resolution has to be set before loading the image, that's why we have to destroy the instance and load it again
         $res = $this->resource->getImageResolution();
         $x_ratio = $res['x'] / $this->getWidth();
         $y_ratio = $res['y'] / $this->getHeight();
         $this->resource->removeImage();
         $newRes = ["x" => $width * $x_ratio, "y" => $height * $y_ratio];
         // only use the calculated resolution if we need a higher one that the one we got from the metadata (getImageResolution)
         // this is because sometimes the quality is much better when using the "native" resulution from the metadata
         if ($newRes["x"] > $res["x"] && $newRes["y"] > $res["y"]) {
             $this->resource->setResolution($newRes["x"], $newRes["y"]);
         } else {
             $this->resource->setResolution($res["x"], $res["y"]);
         }
         $this->resource->readImage($this->imagePath);
         $this->setColorspaceToRGB();
     }
     $width = (int) $width;
     $height = (int) $height;
     $this->resource->resizeimage($width, $height, \Imagick::FILTER_UNDEFINED, 1, false);
     $this->setWidth($width);
     $this->setHeight($height);
     $this->postModify();
     return $this;
 }
開發者ID:Gerhard13,項目名稱:pimcore,代碼行數:35,代碼來源:Imagick.php


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