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


PHP Imagick::setIteratorIndex方法代碼示例

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


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

示例1: current

 /**
  * {@inheritdoc}
  */
 public function current()
 {
     if (!isset($this->layers[$this->offset])) {
         try {
             $this->resource->setIteratorIndex($this->offset);
             $this->layers[$this->offset] = $this->resource->getImage();
         } catch (\GmagickException $e) {
             throw new RuntimeException(sprintf('Failed to extract layer %d', $this->offset), $e->getCode(), $e);
         }
     }
     return new Image($this->layers[$this->offset]);
 }
開發者ID:Laxman-SM,項目名稱:iron_worker_examples,代碼行數:15,代碼來源:Layers.php

示例2: load

 /**
  * Loads image from $this->file into new Imagick Object.
  *
  * @since 3.5.0
  * @access protected
  *
  * @return true|WP_Error True if loaded; WP_Error on failure.
  */
 public function load()
 {
     if ($this->image instanceof Imagick) {
         return true;
     }
     if (!is_file($this->file) && !preg_match('|^https?://|', $this->file)) {
         return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file);
     }
     /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */
     // Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits
     @ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT));
     try {
         $this->image = new Imagick($this->file);
         if (!$this->image->valid()) {
             return new WP_Error('invalid_image', __('File is not an image.'), $this->file);
         }
         // Select the first frame to handle animated images properly
         if (is_callable(array($this->image, 'setIteratorIndex'))) {
             $this->image->setIteratorIndex(0);
         }
         $this->mime_type = $this->get_mime_type($this->image->getImageFormat());
     } catch (Exception $e) {
         return new WP_Error('invalid_image', $e->getMessage(), $this->file);
     }
     $updated_size = $this->update_size();
     if (is_wp_error($updated_size)) {
         return $updated_size;
     }
     return $this->set_quality();
 }
開發者ID:sonvq,項目名稱:passioninvestment,代碼行數:38,代碼來源:class-wp-image-editor-imagick.php

示例3: createImageFromNonImage

 /**
  * Create a image from a non image file content. (Ex. PDF, PSD or TIFF)
  *
  * @param $content
  * @param string $format
  *
  * @return bool|string
  */
 public static function createImageFromNonImage($content, $format = 'jpeg')
 {
     if (!extension_loaded('imagick')) {
         return false;
     }
     $image = new \Imagick();
     $image->readImageBlob($content);
     $image->setIteratorIndex(0);
     $image->setImageFormat($format);
     return $image->getImageBlob();
 }
開發者ID:jel-massih,項目名稱:directus,代碼行數:19,代碼來源:Thumbnail.php

示例4: getImageAtIndex

 /**
  * Request a specific image from the collection of images.
  *
  * @param integer $index  The index to return
  *
  * @return Horde_Image_Base
  */
 public function getImageAtIndex($index)
 {
     if ($index >= $this->_imagick->getNumberImages()) {
         throw Horde_Image_Exception('Image index out of bounds.');
     }
     $currentIndex = $this->_imagick->getIteratorIndex();
     $this->_imagick->setIteratorIndex($index);
     $image = $this->current();
     $this->_imagick->setIteratorIndex($currentIndex);
     return $image;
 }
開發者ID:jubinpatel,項目名稱:horde,代碼行數:18,代碼來源:Imagick.php

示例5: getSize

 /**
  * {@inheritdoc}
  */
 public function getSize()
 {
     try {
         $i = $this->imagick->getIteratorIndex();
         $this->imagick->rewind();
         $width = $this->imagick->getImageWidth();
         $height = $this->imagick->getImageHeight();
         $this->imagick->setIteratorIndex($i);
     } catch (\ImagickException $e) {
         throw new RuntimeException('Could not get size', $e->getCode(), $e);
     }
     return new Box($width, $height);
 }
開發者ID:scisahaha,項目名稱:generator-craft,代碼行數:16,代碼來源:Image.php

示例6: offsetUnset

 /**
  * {@inheritdoc}
  */
 public function offsetUnset($offset)
 {
     try {
         $this->extractAt($offset);
     } catch (RuntimeException $e) {
         return;
     }
     try {
         $this->resource->setIteratorIndex($offset);
         $this->resource->removeImage();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Unable to remove layer', $e->getCode(), $e);
     }
 }
開發者ID:mm999,項目名稱:EduSoho,代碼行數:17,代碼來源:Layers.php

示例7: load

 /**
  * Loads image from $this->file into new Imagick Object.
  *
  * @since 3.5.0
  * @access protected
  *
  * @return true|WP_Error True if loaded; WP_Error on failure.
  */
 public function load()
 {
     if ($this->image instanceof Imagick) {
         return true;
     }
     if (!is_file($this->file) && !preg_match('|^https?://|', $this->file)) {
         return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file);
     }
     /*
      * Even though Imagick uses less PHP memory than GD, set higher limit
      * for users that have low PHP.ini limits.
      */
     wp_raise_memory_limit('image');
     try {
         $this->image = new Imagick();
         $file_parts = pathinfo($this->file);
         $filename = $this->file;
         // By default, PDFs are rendered in a very low resolution.
         // We want the thumbnail to be readable, so increase the rendering dpi.
         if ('pdf' == strtolower($file_parts['extension'])) {
             $this->image->setResolution(128, 128);
             // Only load the first page.
             $filename .= '[0]';
         }
         // Reading image after Imagick instantiation because `setResolution`
         // only applies correctly before the image is read.
         $this->image->readImage($filename);
         if (!$this->image->valid()) {
             return new WP_Error('invalid_image', __('File is not an image.'), $this->file);
         }
         // Select the first frame to handle animated images properly
         if (is_callable(array($this->image, 'setIteratorIndex'))) {
             $this->image->setIteratorIndex(0);
         }
         $this->mime_type = $this->get_mime_type($this->image->getImageFormat());
     } catch (Exception $e) {
         return new WP_Error('invalid_image', $e->getMessage(), $this->file);
     }
     $updated_size = $this->update_size();
     if (is_wp_error($updated_size)) {
         return $updated_size;
     }
     return $this->set_quality();
 }
開發者ID:aaemnnosttv,項目名稱:develop.git.wordpress.org,代碼行數:52,代碼來源:class-wp-image-editor-imagick.php

示例8: createVariation

 /**
  * {@inheritdoc}
  */
 public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null)
 {
     $src = $this->getTempFile($this->data);
     $img = new \Imagick();
     $img->setResolution($this->resolution, $this->resolution);
     $img->readImage($src);
     $img->setIteratorIndex(0);
     // Flatten images here helps the encoder to get rid of the black background
     // that appears on encoded image files.
     $img = $img->flattenImages();
     $img->setImageFormat((string) $output_format->value());
     $img->setImageCompressionQuality($quality);
     if (null !== $crop_dimensions) {
         $img->cropImage($crop_dimensions->getWidth(), $crop_dimensions->getHeight(), $crop_dimensions->getX(), $crop_dimensions->getY());
     }
     if (null !== $dimensions) {
         $img->resizeImage($dimensions->getWidth() ?: 0, $dimensions->getHeight() ?: 0, $this->filter, 1, false);
     }
     return $img->getImageBlob();
 }
開發者ID:bravo3,項目名稱:image-manager,代碼行數:23,代碼來源:ImagickEncoder.php

示例9: load

 /**
  * Loads image from $this->file into new Imagick Object.
  *
  * @since 3.5.0
  * @access protected
  *
  * @return true|WP_Error True if loaded; WP_Error on failure.
  */
 public function load()
 {
     if ($this->image instanceof Imagick) {
         return true;
     }
     if (!is_file($this->file) && !preg_match('|^https?://|', $this->file)) {
         return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file);
     }
     /*
      * Even though Imagick uses less PHP memory than GD, set higher limit
      * for users that have low PHP.ini limits.
      */
     wp_raise_memory_limit('image');
     try {
         $this->image = new Imagick();
         $file_extension = strtolower(pathinfo($this->file, PATHINFO_EXTENSION));
         $filename = $this->file;
         if ('pdf' == $file_extension) {
             $filename = $this->pdf_setup();
         }
         // Reading image after Imagick instantiation because `setResolution`
         // only applies correctly before the image is read.
         $this->image->readImage($filename);
         if (!$this->image->valid()) {
             return new WP_Error('invalid_image', __('File is not an image.'), $this->file);
         }
         // Select the first frame to handle animated images properly
         if (is_callable(array($this->image, 'setIteratorIndex'))) {
             $this->image->setIteratorIndex(0);
         }
         $this->mime_type = $this->get_mime_type($this->image->getImageFormat());
     } catch (Exception $e) {
         return new WP_Error('invalid_image', $e->getMessage(), $this->file);
     }
     $updated_size = $this->update_size();
     if (is_wp_error($updated_size)) {
         return $updated_size;
     }
     return $this->set_quality();
 }
開發者ID:CompositeUK,項目名稱:clone.WordPress-Core,代碼行數:48,代碼來源:class-wp-image-editor-imagick.php

示例10: make_thumbnail_Imagick

 private function make_thumbnail_Imagick($src_path, $width, $height, $dest)
 {
     $image = new Imagick($src_path);
     # Select the first frame to handle animated images properly
     if (is_callable(array($image, 'setIteratorIndex'))) {
         $image->setIteratorIndex(0);
     }
     // устанавливаем качество
     $format = $image->getImageFormat();
     if ($format == 'JPEG' || $format == 'JPG') {
         $image->setImageCompression(Imagick::COMPRESSION_JPEG);
     }
     $image->setImageCompressionQuality(85);
     $h = $image->getImageHeight();
     $w = $image->getImageWidth();
     // если не указана одна из сторон задаем ей пропорциональное значение
     if (!$width) {
         $width = round($w * ($height / $h));
     }
     if (!$height) {
         $height = round($h * ($width / $w));
     }
     list($dx, $dy, $wsrc, $hsrc) = $this->crop_coordinates($height, $h, $width, $w);
     // обрезаем оригинал
     $image->cropImage($wsrc, $hsrc, $dx, $dy);
     $image->setImagePage($wsrc, $hsrc, 0, 0);
     // Strip out unneeded meta data
     $image->stripImage();
     // уменьшаем под размер
     $image->scaleImage($width, $height);
     $image->writeImage($dest);
     chmod($dest, 0755);
     $image->clear();
     $image->destroy();
     return true;
 }
開發者ID:stanislav-chechun,項目名稱:campus-rize,代碼行數:36,代碼來源:rcl_crop.php

示例11: loadPdf

 /**
  * Load a PDF for use on the printer
  *
  * @param string $pdfFile The file to load
  * @param string $pageWidth The width, in pixels, of the printer's output. The first page of the PDF will be scaled to approximately fit in this area.
  * @param array $range array indicating the first and last page (starting from 0) to load. If not set, the entire document is loaded.
  * @throws Exception Where Imagick is not loaded, or where a missing file or invalid page number is requested.
  * @return multitype:EscposImage Array of images, retrieved from the PDF file.
  */
 public static function loadPdf($pdfFile, $pageWidth = 550)
 {
     if (!extension_loaded('imagick')) {
         throw new Exception(__FUNCTION__ . " requires imagick extension.");
     }
     /*
      * Load first page at very low density (resolution), to figure out what
      * density to use to achieve $pageWidth
      */
     try {
         $image = new \Imagick();
         $testRes = 2;
         // Test resolution
         $image->setresolution($testRes, $testRes);
         /* Load document just to measure geometry */
         $image->readimage($pdfFile);
         $geo = $image->getimagegeometry();
         $image->destroy();
         $width = $geo['width'];
         $newRes = $pageWidth / $width * $testRes;
         /* Load entire document in */
         $image->setresolution($newRes, $newRes);
         $image->readImage($pdfFile);
         $pages = $image->getNumberImages();
         /* Convert images to Escpos objects */
         $ret = array();
         for ($i = 0; $i < $pages; $i++) {
             $image->setIteratorIndex($i);
             $ep = new EscposImage();
             $ep->readImageFromImagick($image);
             $ret[] = $ep;
         }
         return $ret;
     } catch (\ImagickException $e) {
         // Wrap in normal exception, so that classes which call this do not themselves require imagick as a dependency.
         throw new Exception($e);
     }
 }
開發者ID:jslemmer,項目名稱:cafe,代碼行數:47,代碼來源:EscposImage.php

示例12: generate_adobe_thumb

 private function generate_adobe_thumb($working_dir, $input_filename, $output_filename)
 {
     $pos = strrpos($input_filename, ".");
     $input_extension = substr($input_filename, $pos + 1);
     $input_path = $working_dir . "/{$input_filename}";
     $output_extension = "png";
     $image = new Imagick($input_path);
     $image->setResolution(300, 300);
     $image->setImageFormat($output_extension);
     if ($input_extension == "psd") {
         $image->setIteratorIndex(0);
     }
     $success = $image->writeImage($working_dir . "/{$output_filename}");
     return $success;
 }
開發者ID:arudd561,項目名稱:pl,代碼行數:15,代碼來源:class-wpd-public.php

示例13: Imagick

<?php

//	error_reporting(E_ERROR | E_WARNING);
$im = new Imagick('logo.psd');
$im->setImageIndex(0);
$im->setIteratorIndex(0);
$im->stripImage();
//去除圖片信息
$im->setImageCompressionQuality(80);
//圖片質量
$im->writeImage('logo.jpg');
echo "<img src='logo.jpg'/>";
開發者ID:sunxguo,項目名稱:image,代碼行數:12,代碼來源:psd.php

示例14: generateThumbnail

 public static function generateThumbnail($localPath, $format, $thumbnailSize, $cropEnabled)
 {
     switch ($format) {
         case 'jpg':
         case 'jpeg':
             // $img = imagecreatefromjpeg($localPath);
             $img = imagecreatefromstring($localPath);
             break;
         case 'gif':
             // $img = imagecreatefromgif($localPath);
             $img = imagecreatefromstring($localPath);
             break;
         case 'png':
             // $img = imagecreatefrompng($localPath);
             $img = imagecreatefromstring($localPath);
             break;
         case 'pdf':
         case 'psd':
         case 'tif':
         case 'tiff':
         case 'svg':
             if (extension_loaded('imagick')) {
                 $image = new \Imagick();
                 $image->readImageBlob($localPath);
                 $image->setIteratorIndex(0);
                 $image->setImageFormat('jpeg');
                 $img = $image->getImageBlob();
             } else {
                 return false;
             }
             break;
         default:
             return false;
     }
     $w = imagesx($img);
     $h = imagesy($img);
     $x1 = 0;
     // used for crops
     $y1 = 0;
     // used for crops
     $aspectRatio = $w / $h;
     if ($cropEnabled) {
         // crop to center of image
         if ($aspectRatio <= 1) {
             $newW = $thumbnailSize;
             $newH = $h * ($thumbnailSize / $w);
             $y1 = -1 * (($newH - $thumbnailSize) / 2);
         } else {
             $newH = $thumbnailSize;
             $newW = $w * ($thumbnailSize / $h);
             $x1 = -1 * (($newW - $thumbnailSize) / 2);
         }
     } else {
         // portrait (or square) mode, maximize height
         if ($aspectRatio <= 1) {
             $newH = $thumbnailSize;
             $newW = $thumbnailSize * $aspectRatio;
         }
         // landscape mode, maximize width
         if ($aspectRatio > 1) {
             $newW = $thumbnailSize;
             $newH = $thumbnailSize / $aspectRatio;
         }
     }
     if ($cropEnabled) {
         $imgResized = imagecreatetruecolor($thumbnailSize, $thumbnailSize);
     } else {
         $imgResized = imagecreatetruecolor($newW, $newH);
     }
     // Preserve transperancy for gifs and pngs
     if ($format == 'gif' || $format == 'png') {
         imagealphablending($imgResized, false);
         imagesavealpha($imgResized, true);
         $transparent = imagecolorallocatealpha($imgResized, 255, 255, 255, 127);
         imagefilledrectangle($imgResized, 0, 0, $newW, $newH, $transparent);
     }
     imagecopyresampled($imgResized, $img, $x1, $y1, 0, 0, $newW, $newH, $w, $h);
     imagedestroy($img);
     return $imgResized;
 }
開發者ID:YounessTayer,項目名稱:directus,代碼行數:80,代碼來源:Thumbnail.php

示例15: _reflection

 protected function _reflection($height, $opacity, $fade_in)
 {
     if ($this->_version >= 30100) {
         $reflection = clone $this->_image;
     } else {
         $reflection = clone $this->_image->{$clone}();
     }
     $reflection->setIteratorIndex(0);
     while (true) {
         $reflection->flipImage();
         $reflection->cropImage($reflection->getImageWidth(), $height, 0, 0);
         $reflection->setImagePage($reflection->getImageWidth(), $height, 0, 0);
         if (!$reflection->nextImage()) {
             break;
         }
     }
     $pseudo = $fade_in ? "gradient:black-transparent" : "gradient:transparent-black";
     $fade = new \Imagick();
     $fade->newPseudoImage($reflection->getImageWidth(), $reflection->getImageHeight(), $pseudo);
     $opacity /= 100;
     $reflection->setIteratorIndex(0);
     while (true) {
         $reflection->compositeImage($fade, constant("Imagick::COMPOSITE_DSTOUT"), 0, 0);
         $reflection->evaluateImage(constant("Imagick::EVALUATE_MULTIPLY"), $opacity / 100, constant("Imagick::CHANNEL_ALPHA"));
         if (!$reflection->nextImage()) {
             break;
         }
     }
     $fade->destroy();
     $image = new \Imagick();
     $pixel = new \ImagickPixel();
     $height = $this->_image->getImageHeight() + $height;
     $this->_image->setIteratorIndex(0);
     while (true) {
         $image->newImage($this->_width, $height, $pixel);
         $image->setImageAlphaChannel(constant("Imagick::ALPHACHANNEL_SET"));
         $image->setColorspace($this->_image->getColorspace());
         $image->setImageDelay($this->_image->getImageDelay());
         $image->compositeImage($this->_image, constant("Imagick::COMPOSITE_SRC"), 0, 0);
         if (!$this->_image->nextImage()) {
             break;
         }
     }
     $image->setIteratorIndex(0);
     $reflection->setIteratorIndex(0);
     while (true) {
         $image->compositeImage($reflection, constant("Imagick::COMPOSITE_OVER"), 0, $this->_height);
         $image->setImageAlphaChannel(constant("Imagick::ALPHACHANNEL_SET"));
         $image->setColorspace($this->_image->getColorspace());
         $image->setImageDelay($this->_image->getImageDelay());
         $image->compositeImage($this->_image, constant("Imagick::COMPOSITE_SRC"), 0, 0);
         if (!$image->nextImage() || !$reflection->nextImage()) {
             break;
         }
     }
     $reflection->destroy();
     $this->_image->clear();
     $this->_image->destroy();
     $this->_image = $image;
     $this->_width = $this->_image->getImageWidth();
     $this->_height = $this->_image->getImageHeight();
 }
開發者ID:smallmirror62,項目名稱:framework,代碼行數:62,代碼來源:Imagick.php


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