当前位置: 首页>>代码示例>>PHP>>正文


PHP resource::setImageFormat方法代码示例

本文整理汇总了PHP中resource::setImageFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::setImageFormat方法的具体用法?PHP resource::setImageFormat怎么用?PHP resource::setImageFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在resource的用法示例。


在下文中一共展示了resource::setImageFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * 保存图像
  * @param  string  $imgname   图像保存名称
  * @param  string  $type      图像类型
  * @param  boolean $interlace 是否对JPEG类型图像设置隔行扫描
  */
 public function save($imgname, $type = null, $interlace = true)
 {
     if (empty($this->img)) {
         throw new Exception('没有可以被保存的图像资源');
     }
     //设置图片类型
     if (is_null($type)) {
         $type = $this->info['type'];
     } else {
         $type = strtolower($type);
         $this->img->setImageFormat($type);
     }
     //JPEG图像设置隔行扫描
     if ('jpeg' == $type || 'jpg' == $type) {
         $this->img->setImageInterlaceScheme(1);
     }
     //去除图像配置信息
     $this->img->stripImage();
     //保存图像
     $imgname = realpath(dirname($imgname)) . '/' . basename($imgname);
     //强制绝对路径
     if ('gif' == $type) {
         $this->img->writeImages($imgname, true);
     } else {
         $this->img->writeImage($imgname);
     }
 }
开发者ID:a3147972,项目名称:wswl,代码行数:33,代码来源:Imagick.class.php

示例2: save

 public function save($imgname, $type = NULL, $interlace = true)
 {
     if (empty($this->img)) {
         throw new Exception("没有可以被保存的图像资源");
     }
     if (is_null($type)) {
         $type = $this->info["type"];
     } else {
         $type = strtolower($type);
         $this->img->setImageFormat($type);
     }
     if ("jpeg" == $type || "jpg" == $type) {
         $this->img->setImageInterlaceScheme(1);
     }
     $this->img->stripImage();
     $imgname = realpath(dirname($imgname)) . "/" . basename($imgname);
     if ("gif" == $type) {
         $this->img->writeImages($imgname, true);
     } else {
         $this->img->writeImage($imgname);
     }
 }
开发者ID:AxelPanda,项目名称:ibos,代码行数:22,代码来源:ImageImagick.class.php

示例3: output

 /**
  * {@inheritdoc}
  */
 public function output($format = null)
 {
     if ($this->isBlank()) {
         throw new EmptyImageException('You are trying to output an empty image.');
     }
     try {
         $format = $this->getFormat();
     } catch (ImagickException $e) {
         $this->setFormat('jpg');
     }
     if ($format !== null) {
         $this->resource->setImageFormat($format);
     }
     return $this->resource->getImagesBlob();
 }
开发者ID:basekit,项目名称:imanee,代码行数:18,代码来源:ImagickResource.php

示例4: setImage

 /**
  * 读取图片
  * @param string $image 图片路径
  */
 public function setImage($image)
 {
     if (is_string($image)) {
         $opts = array('http' => array('timeout' => 5));
         $context = stream_context_create($opts);
         $times = 0;
         do {
             self::$fd = fopen($image, 'r', $include_path = false, $context);
             if (++$times >= 3) {
                 break;
             }
         } while (self::$fd === false);
         self::$resource->readImage(self::$fd);
         self::$resourcek = self::$resource->clone();
     } else {
         if (is_array($image)) {
             self::$resource->newImage($image['width'], $image['height'], $image['backgroundColor']);
             self::$resource->setImageFormat($image['format']);
         }
     }
 }
开发者ID:az0ne,项目名称:diaoyu,代码行数:25,代码来源:BaseModelImage.php

示例5: imageAddText

 /**
  * Add watermark text to image
  *
  * @param resource $image
  * @param array $opt
  * @return resource
  */
 private function imageAddText($image, $color, $text)
 {
     if (osc_use_imagick()) {
         $draw = new ImagickDraw();
         $draw->setFillColor('black');
         //$color);
         $draw->setFont($this->font);
         $draw->setFontSize(30);
         $metrics = $image->queryFontMetrics($draw, $text);
         $geometry = $image->getImageGeometry();
         switch (osc_watermark_place()) {
             case 'tl':
                 $offset['x'] = 1;
                 $offset['y'] = $metrics['ascender'] + 1;
                 break;
             case 'tr':
                 $offset['x'] = $geometry['width'] - $metrics['textWidth'] - 1;
                 $offset['y'] = $metrics['ascender'] + 1;
                 break;
             case 'bl':
                 $offset['x'] = 1;
                 $offset['y'] = $geometry['height'] - 1;
                 break;
             case 'br':
                 $offset['x'] = $geometry['width'] - $metrics['textWidth'] - 1;
                 $offset['y'] = $geometry['height'] - 1;
                 break;
             default:
                 $offset['x'] = $geometry['width'] / 2 - $metrics['textWidth'] / 2;
                 $offset['y'] = $geometry['height'] / 2 - $metrics['ascender'] / 2;
                 break;
         }
         $image->annotateImage($draw, $offset['x'], $offset['y'], 0, $text);
         $image->setImageFormat('jpg');
     } else {
         // allocate text color
         $color = $this->imageColorAllocateHex($image, $color);
         // calculate watermark position and get full path to font file
         $offset = $this->calculateOffset($image, $text);
         // Add the text to image
         imagettftext($image, 20, 0, $offset['x'], $offset['y'], $color, $this->font, html_entity_decode($text, null, "UTF-8"));
     }
     return $image;
 }
开发者ID:nsswaga,项目名称:OSClass,代码行数:51,代码来源:Watermark.php

示例6: imagickImage

 /**
  * Output imagick image to file
  *
  * @param resource $img imagick image resource
  * @param string $filename The path to save the file to.
  * @param string $destformat The Image type to use for $filename
  * @param int $jpgQuality JEPG quality (1-100)
  * @return bool
  */
 protected function imagickImage($img, $filename, $destformat, $jpgQuality = null)
 {
     if (!$jpgQuality) {
         $jpgQuality = $this->options['jpgQuality'];
     }
     try {
         if ($destformat) {
             if ($destformat === 'gif') {
                 $img->setImageFormat('gif');
             } else {
                 if ($destformat === 'png') {
                     $img->setImageFormat('png');
                 } else {
                     if ($destformat === 'jpg') {
                         $img->setImageFormat('jpeg');
                     }
                 }
             }
         }
         if (strtoupper($img->getImageFormat()) === 'JPEG') {
             $img->setImageCompression(imagick::COMPRESSION_JPEG);
             $img->setImageCompressionQuality($jpgQuality);
             try {
                 $orientation = $img->getImageOrientation();
             } catch (ImagickException $e) {
                 $orientation = 0;
             }
             $img->stripImage();
             if ($orientation) {
                 $img->setImageOrientation($orientation);
             }
         }
         $result = $img->writeImage($filename);
     } catch (Exception $e) {
         $result = false;
     }
     return $result;
 }
开发者ID:lalusaud,项目名称:mysite,代码行数:47,代码来源:elFinderVolumeDriver.class.php


注:本文中的resource::setImageFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。