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


PHP Imagick::setResolution方法代碼示例

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


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

示例1: convert_to_IMG

function convert_to_IMG($attachment, $options)
{
    $path = get_path($attachment);
    $dir = get_dir($attachment);
    $basename = get_basename($attachment);
    $converted_images = array();
    $max_width = $options['max_width'] ? (int) $options['max_width'] : 0;
    $max_height = $options['max_height'] ? (int) $options['max_height'] : 0;
    $img_extension = $options['img_extension'] ? $options['img_extension'] : 'jpg';
    $pages_to_convert = $options["pages_to_convert"] ? (int) $options["pages_to_convert"] : 0;
    if ($pages_to_convert > 5) {
        $pages_to_convert = 5;
    }
    $pages_to_convert = $pages_to_convert - 1;
    $quality = $options['quality'] ? (int) $options['quality'] : 80;
    if ($quality > 100) {
        $quality = 100;
    }
    try {
        $imagick = new Imagick();
        $imagick->clear();
        $imagick->destroy();
        if ($options) {
            $imagick->setResolution(150, 150);
            $imagick->readimage($path);
            $imagick->setCompressionQuality($quality);
        } else {
            $imagick->setResolution(72, 72);
            $imagick->readimage($path);
        }
        foreach ($imagick as $c => $_page) {
            if ($pages_to_convert == -1 || $c <= $pages_to_convert) {
                $_page->setImageBackgroundColor('white');
                $_page->setImageFormat($img_extension);
                if ($max_width && $max_height) {
                    $_page->adaptiveResizeImage($max_width, $max_height, true);
                }
                $blankPage = new \Imagick();
                $blankPage->newPseudoImage($_page->getImageWidth(), $_page->getImageHeight(), "canvas:white");
                $blankPage->compositeImage($_page, \Imagick::COMPOSITE_OVER, 0, 0);
                if ($blankPage->writeImage($dir . "/" . $basename . '-' . $c . '.' . $img_extension)) {
                    array_push($converted_images, $dir . "/" . $basename . '-' . $c . '.' . $img_extension);
                }
                $blankPage->clear();
                $blankPage->destroy();
            }
        }
    } catch (ImagickException $e) {
        $converted_images = false;
    } catch (Exception $e) {
        $converted_images = false;
    }
    return $converted_images;
}
開發者ID:fedorenko-dmitriy,項目名稱:pdf2img-converter,代碼行數:54,代碼來源:core.php

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

示例3: getPage

 function getPage($page)
 {
     $format = $this->parameters['format_image'];
     switch ($format) {
         case "imagick":
         case "png":
             $extension = "png";
             $content_type = "image/x-png";
             break;
         case "jpeg":
             $extension = "jpg";
             $content_type = "image/jpeg";
             break;
     }
     $len = strlen($this->getPageCount());
     if (!file_exists($this->doc->driver->get_cached_filename($this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . "." . $extension)) {
         $resolution = $this->parameters['resolution_image'];
         if ($format == "imagick") {
             exec("pdftoppm -f {$page} -l {$page} -r " . $resolution . " " . $this->doc->driver->get_cached_filename($this->doc->id) . " " . $this->doc->driver->get_cached_filename("page_" . $this->doc->id));
             $imagick = new Imagick();
             $imagick->setResolution($resolution, $resolution);
             $imagick->readImage($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . ".ppm");
             $imagick->writeImage($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . ".png");
             unlink($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . ".ppm");
         } else {
             exec("pdftoppm -f {$page} -l {$page} -r " . $resolution . " -" . $format . " " . $this->doc->driver->get_cached_filename($this->doc->id) . " " . $this->doc->driver->get_cached_filename("page_" . $this->doc->id));
         }
     }
     if (file_exists($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . "." . $extension)) {
         header("Content-Type: " . $content_type);
         print file_get_contents($this->doc->driver->get_cached_filename("page_" . $this->doc->id) . "-" . str_pad($page, $len, "0", STR_PAD_LEFT) . "." . $extension);
     }
 }
開發者ID:noble82,項目名稱:proyectos-ULS,代碼行數:33,代碼來源:bookreaderPDF.class.php

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

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

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

示例7: convert

 private function convert($item, $page)
 {
     $im = new Imagick($item->internalPath() . '[' . ($page - 1) . ']');
     $im->setResolution(1600, 1600);
     $im->setImageFormat('jpg');
     header('Content-Type: image/jpeg');
     echo $im;
     die;
 }
開發者ID:Zveroloff,項目名稱:kloudspeaker,代碼行數:9,代碼來源:PDF.viewer.php

示例8: processFileToImageCache

 /**
  * Write a rendered PDF to the cache.
  *
  * @param $filePath
  * @param $cacheLocation
  */
 protected function processFileToImageCache($filePath, $cacheLocation)
 {
     if (!is_dir($cacheLocation)) {
         mkdir($cacheLocation);
     }
     $imagick = new \Imagick();
     $imagick->setResolution(150, 150);
     $imagick->readImage($filePath);
     $imagick->writeImages($cacheLocation . '/rendered.jpg', true);
 }
開發者ID:aaronsaray,項目名稱:aaronsaray.com,代碼行數:16,代碼來源:index.php

示例9: resize

 /**
  * @param  $width
  * @param  $height
  * @return Pimcore_Image_Adapter
  */
 public function resize($width, $height)
 {
     // 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->resource->getImageWidth();
         $y_ratio = $res['y'] / $this->resource->getImageHeight();
         $this->resource->removeImage();
         $this->resource->setResolution($width * $x_ratio, $height * $y_ratio);
         $this->resource->readImage($this->imagePath);
     } else {
         $this->resource->resizeimage($width, $height, Imagick::FILTER_UNDEFINED, 1, false);
     }
     $this->setWidth($width);
     $this->setHeight($height);
     $this->reinitializeImage();
     return $this;
 }
開發者ID:nblackman,項目名稱:pimcore,代碼行數:25,代碼來源:Imagick.php

示例10: pdf_setup

 /**
  * Sets up Imagick for PDF processing.
  * Increases rendering DPI and only loads first page.
  *
  * @since 4.7.0
  * @access protected
  *
  * @return string|WP_Error File to load or WP_Error on failure.
  */
 protected function pdf_setup()
 {
     try {
         // By default, PDFs are rendered in a very low resolution.
         // We want the thumbnail to be readable, so increase the rendering DPI.
         $this->image->setResolution(128, 128);
         // Only load the first page.
         return $this->file . '[0]';
     } catch (Exception $e) {
         return new WP_Error('pdf_setup_failed', $e->getMessage(), $this->file);
     }
 }
開發者ID:johnpbloch,項目名稱:wordpress,代碼行數:21,代碼來源:class-wp-image-editor-imagick.php

示例11: create

 public function create($width, $height, $format = 'png')
 {
     // Destroy first?
     $this->destroy();
     // Create
     $resource = new Imagick();
     $resource->setResolution($width, $height);
     $resource->newImage(100, 100, new ImagickPixel('none'), $format);
     $resource->setImageFormat($format);
     // Save resource
     $this->_resource = $resource;
     return $this;
 }
開發者ID:febryantosulistyo,項目名稱:ClassicSocial,代碼行數:13,代碼來源:Imagick.php

示例12: imgetimagesize

	function imgetimagesize($imagefile) {
		if (class_exists('Imagick')) {
			$im = new Imagick();
			$im->setResolution( 300, 300 );
			$im->readImage($imagefile);
			$width = $im->getImageWidth();
			$height = $im->getImageHeight();
			$type = $im->getImageType();
			$attr = "width=\"$width\" height=\"$height\"";
		} else {
			list($width, $height, $type, $attr) = getimagesize($imagefile);
		}
		return array($width, $height, $type, $attr);
	}
開發者ID:avryhof,項目名稱:digital-asset-manager,代碼行數:14,代碼來源:image_functions.php

示例13: 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&#8217;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

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

示例15: resize

 /**
  * @param  $width
  * @param  $height
  * @return Pimcore_Image_Adapter
  */
 public function resize($width, $height)
 {
     // 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
     $type = $this->resource->getimageformat();
     $vectorTypes = array("EPT", "EPDF", "EPI", "EPS", "EPS2", "EPS3", "EPSF", "EPSI", "EPT", "PDF", "PFA", "PFB", "PFM", "PS", "PS2", "PS3", "PSB", "SVG", "SVGZ");
     if (in_array($type, $vectorTypes)) {
         // 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->resource->getImageWidth();
         $y_ratio = $res['y'] / $this->resource->getImageHeight();
         $this->resource->removeImage();
         $this->resource->setResolution($width * $x_ratio, $height * $y_ratio);
         $this->resource->readImage($this->imagePath);
     } else {
         $this->resource->resizeimage($width, $height, Imagick::FILTER_UNDEFINED, 1, false);
     }
     $this->setWidth($width);
     $this->setHeight($height);
     $this->reinitializeImage();
     return $this;
 }
開發者ID:ngocanh,項目名稱:pimcore,代碼行數:27,代碼來源:Imagick.php


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