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


PHP imagick::getImageColorspace方法代码示例

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


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

示例1: imgSquareFit

 /**
  * Put image to square
  *
  * @param  string   $path               image file
  * @param  int      $width              square width
  * @param  int      $height             square height
  * @param  int	    $align              reserved
  * @param  int 	    $valign             reserved
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  **/
 protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     /* Coordinates for image over square aligning */
     $y = ceil(abs($height - $s[1]) / 2);
     $x = ceil(abs($width - $s[0]) / 2);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img1 = new Imagick();
             $img1->newImage($width, $height, new ImagickPixel($bgcolor));
             $img1->setImageColorspace($img->getImageColorspace());
             $img1->setImageFormat($destformat != null ? $destformat : $img->getFormat());
             $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
             $result = $img1->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $img = imagecreatefromjpeg($path);
             } elseif ($s['mime'] == 'image/png') {
                 $img = imagecreatefrompng($path);
             } elseif ($s['mime'] == 'image/gif') {
                 $img = imagecreatefromgif($path);
             } elseif ($s['mime'] == 'image/xbm') {
                 $img = imagecreatefromxbm($path);
             }
             if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                 if ($bgcolor == 'transparent') {
                     list($r, $g, $b) = array(0, 0, 255);
                 } else {
                     list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
                 }
                 $bgcolor1 = imagecolorallocate($tmp, $r, $g, $b);
                 if ($bgcolor == 'transparent') {
                     $bgcolor1 = imagecolortransparent($tmp, $bgcolor1);
                 }
                 imagefill($tmp, 0, 0, $bgcolor1);
                 if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
                     return false;
                 }
                 if ($destformat == 'jpg' || $destformat == null && $s['mime'] == 'image/jpeg') {
                     $result = imagejpeg($tmp, $path, 100);
                 } else {
                     if ($destformat == 'gif' || $destformat == null && $s['mime'] == 'image/gif') {
                         $result = imagegif($tmp, $path, 7);
                     } else {
                         $result = imagepng($tmp, $path, 7);
                     }
                 }
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
开发者ID:serhatozles,项目名称:yii2-elfinder,代码行数:79,代码来源:elFinderVolumeDriver.class.php

示例2: imgSquareFit

 /**
  * Put image to square
  *
  * @param  string   $path               image file
  * @param  int      $width              square width
  * @param  int      $height             square height
  * @param  int	    $align              reserved
  * @param  int 	    $valign             reserved
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  **/
 protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     /* Coordinates for image over square aligning */
     $y = ceil(abs($height - $s[1]) / 2);
     $x = ceil(abs($width - $s[0]) / 2);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img1 = new Imagick();
             $img1->newImage($width, $height, new ImagickPixel($bgcolor));
             $img1->setImageColorspace($img->getImageColorspace());
             $img1->setImageFormat($destformat != null ? $destformat : $img->getFormat());
             $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
             $result = $img1->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                 self::gdImageBackground($tmp, $bgcolor);
                 if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
                     return false;
                 }
                 $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
开发者ID:hyrmedia,项目名称:builderengine,代码行数:54,代码来源:elFinderVolumeDriver.class.php


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