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


PHP Imagick::readImageBlob方法代碼示例

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


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

示例1: __construct

 /**
  * 初始化imagick對象
  *
  * @param $filepath string 文件地址
  * @param $isBinary boolean 是否是二進製內容或文件地址
  */
 public function __construct($filepath, $isBinary = FALSE)
 {
     parent::__construct();
     $this->image = new \Imagick();
     try {
         // imagick::readImage 在win下5.3版本居然不能直接用。改為readImageBlob可用。
         $this->image->readImageBlob($isBinary ? $filepath : file_get_contents($filepath));
         $this->originalFileSize = $this->image->getimagesize();
     } catch (\ImagickException $e) {
         throw new MediaException($e->getMessage());
     }
 }
開發者ID:ZhuJingfa,項目名稱:HuiLib,代碼行數:18,代碼來源:ImageBase.php

示例2: pdfAction

 public function pdfAction()
 {
     $model = $this->_processSvg();
     $scale = $this->getRequest()->getPost('print_scale');
     $model->addWhiteFontForPDF();
     $data = $model->normalizeSvgData();
     if ($model->getAdditionalData('order_increment_id')) {
         $filename = 'Order_' . $model->getAdditionalData('order_increment_id') . '_Image.pdf';
     } else {
         $filename = 'Customer_Product_Image.pdf';
     }
     $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', 'application/pdf', true)->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true);
     $this->getResponse()->clearBody();
     //$this->getResponse()->setBody(str_replace('xlink:','',$data));
     $imagick = new Imagick();
     $imagick->readImageBlob($data);
     if ($scale != 1 && $scale <= 15) {
         $imagick->scaleImage($scale * $imagick->getImageWidth(), $scale * $imagick->getImageHeight());
     }
     $imagick->setImageFormat("pdf");
     /*$imagick->writeImage(MAGENTO_ROOT.'/media/us-map.pdf');scaleImage */
     $this->getResponse()->setBody($imagick);
     $imagick->clear();
     $imagick->destroy();
 }
開發者ID:Eximagen,項目名稱:BulletMagento,代碼行數:25,代碼來源:IndexController.php

示例3: load

 public function load($bytes)
 {
     $this->image = new $this->image_class();
     $this->image->readImageBlob($bytes);
     $this->update_size($this->image->getImageWidth(), $this->image->getImageHeight(), true);
     return $this;
 }
開發者ID:anp135,項目名稱:altocms,代碼行數:7,代碼來源:Imagick.php

示例4: readBinary

 /**
  * @param mixed  $image
  * @param string $name
  *
  * @throws ProcessorException
  *
  * @returns $this
  */
 public function readBinary($image, $name)
 {
     $this->initialize(true);
     try {
         $this->im->readImageBlob($image, $name);
     } catch (\Exception $e) {
         throw new ProcessorException('Could not read binary image %s: %s', null, $e, (string) $name, (string) $e->getMessage());
     }
     return $this;
 }
開發者ID:scr-be,項目名稱:teavee-image-magic-bundle,代碼行數:18,代碼來源:ImageMagickProcessor.php

示例5: post

 public function post()
 {
     if ($this->validate()) {
         $image = new PhotoActiveRecord();
         $image->userId = Yii::$app->user->identity->id;
         $image->name = $this->name . '';
         $image->photo = file_get_contents($this->file->tempName);
         $image->posted = date('Y-m-d H-i-s');
         $imagick = new \Imagick();
         $imagick->readImageBlob($image->photo);
         $size = $imagick->getImageGeometry();
         if ($size['width'] > 800) {
             foreach ($imagick as $frame) {
                 $frame->thumbnailImage(800, 0);
             }
         }
         $image->thumbnail = $imagick->getImagesBlob();
         if (!$image->save()) {
             return false;
         }
         $tags = split(',', $this->tags);
         foreach ($tags as $item) {
             if ($item != '') {
                 $tag = new TagsActiveRecord();
                 $tag->photo = $image->id;
                 $tag->tag = trim($item);
                 if (!$tag->save()) {
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
開發者ID:kazachka,項目名稱:photo-yii-site,代碼行數:35,代碼來源:LoadForm.php

示例6: get

 public static function get($username)
 {
     $lowercase = strtolower($username);
     $skin = './minecraft/skins/' . $lowercase . '.png';
     if (file_exists($skin)) {
         if (time() - filemtime($skin) < self::$expires) {
             return $lowercase;
         }
         $cached = true;
     }
     $binary = self::fetch('http://s3.amazonaws.com/MinecraftSkins/' . $username . '.png');
     if ($binary === false) {
         if ($cached) {
             return $lowercase;
         }
         header('Status: 404 Not Found');
         return $username == self::DEFAULT_SKIN ? $lowercase : self::get(self::DEFAULT_SKIN);
     }
     $img = new Imagick();
     $img->readImageBlob($binary);
     $img->stripImage();
     // strip metadata
     $img->writeImage($skin);
     self::_getHelm($img)->writeImage('./minecraft/helms/' . $lowercase . '.png');
     self::_getHead($img)->writeImage('./minecraft/heads/' . $lowercase . '.png');
     self::_getPlayer($img)->writeImage('./minecraft/players/' . $lowercase . '.png');
     return $lowercase;
 }
開發者ID:ryantheleach,項目名稱:Minotar,代碼行數:28,代碼來源:Minotar.php

示例7: getThumbnail

	/**
	 * {@inheritDoc}
	 */
	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		try {
			$svg = new \Imagick();
			$svg->setBackgroundColor(new \ImagickPixel('transparent'));

			$content = stream_get_contents($fileview->fopen($path, 'r'));
			if (substr($content, 0, 5) !== '<?xml') {
				$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
			}

			// Do not parse SVG files with references
			if (stripos($content, 'xlink:href') !== false) {
				return false;
			}

			$svg->readImageBlob($content);
			$svg->setImageFormat('png32');
		} catch (\Exception $e) {
			\OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
			return false;
		}

		//new image object
		$image = new \OC_Image();
		$image->loadFromData($svg);
		//check if image object is valid
		if ($image->valid()) {
			$image->scaleDownToFit($maxX, $maxY);

			return $image;
		}
		return false;
	}
開發者ID:ninjasilicon,項目名稱:core,代碼行數:36,代碼來源:svg.php

示例8: loadSVG

 protected function loadSVG($image)
 {
     $this->log('Load SVG image', 2);
     if (!class_exists('Imagick')) {
         $this->log('Fail', 2);
         throw new ImageMagickNotAvailableException();
     }
     $content = @file_get_contents($image);
     if (!is_string($content)) {
         $this->log('Fail', 2);
         throw new InvalidImageException(sprintf('Could not load <info>%s</info>, could not read resource.', $image));
     }
     $image = new \Imagick();
     $image->readImageBlob($content);
     $width = $image->getImageWidth();
     $height = $image->getImageHeight();
     if (310 > $width || 310 > $height) {
         $this->log('Fail', 2);
         throw new InvalidImageException(sprintf('Source image must be at least <info>%s</info>,' . ' actual size is: <info>%s</info>', '310x310', $width . 'x' . $height));
     }
     $image->setImageFormat('png24');
     $this->gd = @imagecreatefromstring((string) $image);
     $image->destroy();
     if (!is_resource($this->gd)) {
         $this->log('Fail', 2);
         throw new InvalidImageException(sprintf('Could not load <info>%s</info>, ImageMagick could not convert' . ' the resource to a valid GD compatible image.', $image));
     }
     $this->log('Success', 2);
     return $this;
 }
開發者ID:TonyBogdanov,項目名稱:faviconr,代碼行數:30,代碼來源:Faviconr.php

示例9: svgToImage

 public function svgToImage($file, $size = array('width' => 100, 'height' => 100), $type = 'png', $fixed = false)
 {
     $image = new Imagick();
     $image->setBackgroundColor(new ImagickPixel('transparent'));
     $data = file_get_contents($this->file);
     $image->readImageBlob($data);
     $image->setImageFormat($type);
     if ($fixed === true) {
         $newWidth = $size['width'];
         $newHeight = $size['height'];
     } else {
         $imageprops = $image->getImageGeometry();
         $width = $imageprops['width'];
         $height = $imageprops['height'];
         if ($width > $height) {
             $newHeight = $size['height'];
             $newWidth = $size['height'] / $height * $width;
         } else {
             $newWidth = $size['width'];
             $newHeight = $size['width'] / $width * $height;
         }
     }
     $image->resizeImage($newWidth, $newHeight, imagick::FILTER_LANCZOS, 1);
     $image->writeImage(dirname(__FILE__) . '/image.png');
     $image->clear();
     $image->destroy();
 }
開發者ID:Nnamso,項目名稱:tbox,代碼行數:27,代碼來源:svg.php

示例10: alfath_svg_compiler

function alfath_svg_compiler($options)
{
    global $wp_filesystem;
    if (!class_exists('Imagick')) {
        return new WP_Error('class_not_exist', 'Your server not support imagemagick');
    }
    $im = new Imagick();
    $im->setBackgroundColor(new ImagickPixel('transparent'));
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    $file = get_template_directory() . '/assets/img/nav.svg';
    $target = get_template_directory() . '/assets/img/nav-bg.png';
    if ($wp_filesystem->exists($file)) {
        //check for existence
        $svg = $wp_filesystem->get_contents($file);
        if (!$svg) {
            return new WP_Error('reading_error', 'Error when reading file');
        }
        //return error object
        $svg = preg_replace('/fill="#([0-9a-f]{6})"/', 'fill="' . $options['secondary-color'] . '"', $svg);
        $im->readImageBlob($svg);
        $im->setImageFormat("png24");
        $im->writeImage($target);
        $im->clear();
        $im->destroy();
    } else {
        return new WP_Error('not_found', 'File not found');
    }
}
開發者ID:ArgiaCyber,項目名稱:alfath,代碼行數:31,代碼來源:functions.php

示例11: getPng

 public function getPng($resolutionX = 100, $resolutionY = 100)
 {
     $img = new \Imagick();
     $img->setResolution($resolutionX, $resolutionY);
     $img->readImageBlob($this->get());
     $img->setImageFormat('png');
     return $img->getImageBlob();
 }
開發者ID:garrinar,項目名稱:laravel,代碼行數:8,代碼來源:Pdf.php

示例12: readImageBlob

 /**
  * Inject the image blob from the image model into the shared imagick instance
  *
  * @param EventInterface $event The event instance
  */
 public function readImageBlob(EventInterface $event)
 {
     if ($event->hasArgument('image')) {
         // The image has been specified as an argument to the event
         $image = $event->getArgument('image');
     } else {
         if ($event->getName() === 'images.post') {
             // The image is found in the request
             $image = $event->getRequest()->getImage();
         } else {
             // The image is found in the response
             $image = $event->getResponse()->getModel();
         }
     }
     // Inject the image blob
     $this->imagick->readImageBlob($image->getBlob());
 }
開發者ID:imbo,項目名稱:imbo,代碼行數:22,代碼來源:Imagick.php

示例13: getImageResolution

 /**
  * Return image resolution based on the Image object provided.
  * Please note that this method seems to return the image density, or DPI,
  * not it's output resolution.
  *
  * @param Image $image
  *
  * @return ImageDimensions
  */
 protected function getImageResolution(Image $image)
 {
     if (!$image->isHydrated()) {
         throw new ImageManagerException(ImageManager::ERR_NOT_HYDRATED);
     }
     $img = new \Imagick();
     $img->readImageBlob($image->getData());
     $d = $img->getImageResolution();
     $dimensions = new ImageDimensions($d['x'], $d['y']);
     return $dimensions;
 }
開發者ID:song-yuan,項目名稱:image-manager,代碼行數:20,代碼來源:ImageInspector.php

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

示例15: load

 /**
  * (non-PHPdoc)
  * @see Imagine\ImagineInterface::load()
  */
 public function load($string)
 {
     try {
         $imagick = new \Imagick();
         $imagick->readImageBlob($string);
         $imagick->setImageMatte(true);
         return new Image($imagick);
     } catch (\ImagickException $e) {
         throw new RuntimeException('Could not load image from string', $e->getCode(), $e);
     }
 }
開發者ID:nicodmf,項目名稱:Imagine,代碼行數:15,代碼來源:Imagine.php


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