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


PHP imagick::setBackgroundColor方法代码示例

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


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

示例1: createTmb

 /**
  * Create thumnbnail and return it's URL on success
  *
  * @param  string $path file path
  * @param $stat
  * @return false|string
  * @internal param string $mime file mime type
  * @author Dmitry (dio) Levashov
  */
 protected function createTmb($path, $stat)
 {
     if (!$stat || !$this->canCreateTmb($path, $stat)) {
         return false;
     }
     $name = $this->tmbname($stat);
     $tmb = $this->tmbPath . DIRECTORY_SEPARATOR . $name;
     // copy image into tmbPath so some drivers does not store files on local fs
     if (($src = $this->fopenCE($path, 'rb')) == false) {
         return false;
     }
     if (($trg = fopen($tmb, 'wb')) == false) {
         $this->fcloseCE($src, $path);
         return false;
     }
     while (!feof($src)) {
         fwrite($trg, fread($src, 8192));
     }
     $this->fcloseCE($src, $path);
     fclose($trg);
     $result = false;
     $tmbSize = $this->tmbSize;
     if ($this->imgLib === 'imagick') {
         try {
             $imagickTest = new imagick($tmb);
             $imagickTest->clear();
             $imagickTest = true;
         } catch (Exception $e) {
             $imagickTest = false;
         }
     }
     if ($this->imgLib === 'imagick' && !$imagickTest || ($s = @getimagesize($tmb)) === false) {
         if ($this->imgLib === 'imagick') {
             try {
                 $imagick = new imagick();
                 $imagick->setBackgroundColor(new ImagickPixel($this->options['tmbBgColor']));
                 $imagick->readImage($this->getExtentionByMime($stat['mime'], ':') . $tmb);
                 $imagick->setImageFormat('png');
                 $imagick->writeImage($tmb);
                 $imagick->clear();
                 if (($s = @getimagesize($tmb)) !== false) {
                     $result = true;
                 }
             } catch (Exception $e) {
             }
         }
         if (!$result) {
             unlink($tmb);
             return false;
         }
         $result = false;
     }
     /* If image smaller or equal thumbnail size - just fitting to thumbnail square */
     if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) {
         $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
     } else {
         if ($this->options['tmbCrop']) {
             $result = $tmb;
             /* Resize and crop if image bigger than thumbnail */
             if (!($s[0] > $tmbSize && $s[1] <= $tmbSize || $s[0] <= $tmbSize && $s[1] > $tmbSize) || $s[0] > $tmbSize && $s[1] > $tmbSize) {
                 $result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
             }
             if ($result && ($s = @getimagesize($tmb)) != false) {
                 $x = $s[0] > $tmbSize ? intval(($s[0] - $tmbSize) / 2) : 0;
                 $y = $s[1] > $tmbSize ? intval(($s[1] - $tmbSize) / 2) : 0;
                 $result = $this->imgCrop($result, $tmbSize, $tmbSize, $x, $y, 'png');
             } else {
                 $result = false;
             }
         } else {
             $result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, true, 'png');
         }
         if ($result) {
             $result = $this->imgSquareFit($result, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
         }
     }
     if (!$result) {
         unlink($tmb);
         return false;
     }
     return $name;
 }
开发者ID:lalusaud,项目名称:mysite,代码行数:91,代码来源:elFinderVolumeDriver.class.php

示例2: createTmb

 /**
  * Create thumnbnail and return it's URL on success
  *
  * @param  string $path file path
  * @param $stat
  * @return false|string
  * @internal param string $mime file mime type
  * @author Dmitry (dio) Levashov
  */
 protected function createTmb($path, $stat)
 {
     if (!$stat || !$this->canCreateTmb($path, $stat)) {
         return false;
     }
     $name = $this->tmbname($stat);
     $tmb = $this->tmbPath . DIRECTORY_SEPARATOR . $name;
     $maxlength = -1;
     $imgConverter = null;
     // check imgConverter
     $mime = strtolower($stat['mime']);
     list($type) = explode('/', $mime);
     if (isset($this->imgConverter[$mime])) {
         $imgConverter = $this->imgConverter[$mime]['func'];
         if (!empty($this->imgConverter[$mime]['maxlen'])) {
             $maxlength = intval($this->imgConverter[$mime]['maxlen']);
         }
     } else {
         if (isset($this->imgConverter[$type])) {
             $imgConverter = $this->imgConverter[$type]['func'];
             if (!empty($this->imgConverter[$type]['maxlen'])) {
                 $maxlength = intval($this->imgConverter[$type]['maxlen']);
             }
         }
     }
     if ($imgConverter && !is_callable($imgConverter)) {
         return false;
     }
     // copy image into tmbPath so some drivers does not store files on local fs
     if (($src = $this->fopenCE($path, 'rb')) == false) {
         return false;
     }
     if (($trg = fopen($tmb, 'wb')) == false) {
         $this->fcloseCE($src, $path);
         return false;
     }
     stream_copy_to_stream($src, $trg, $maxlength);
     $this->fcloseCE($src, $path);
     fclose($trg);
     // call imgConverter
     if ($imgConverter) {
         if (!call_user_func_array($imgConverter, array($tmb, $stat, $this))) {
             file_exists($tmb) && unlink($tmb);
             return false;
         }
     }
     $result = false;
     $tmbSize = $this->tmbSize;
     if ($this->imgLib === 'imagick') {
         try {
             $imagickTest = new imagick($tmb);
             $imagickTest->clear();
             $imagickTest = true;
         } catch (Exception $e) {
             $imagickTest = false;
         }
     }
     if ($this->imgLib === 'imagick' && !$imagickTest || ($s = getimagesize($tmb)) === false) {
         if ($this->imgLib === 'imagick') {
             $bgcolor = $this->options['tmbBgColor'];
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             try {
                 $imagick = new imagick();
                 $imagick->setBackgroundColor(new ImagickPixel($bgcolor));
                 $imagick->readImage($this->getExtentionByMime($stat['mime'], ':') . $tmb);
                 $imagick->setImageFormat('png');
                 $imagick->writeImage($tmb);
                 $imagick->clear();
                 if (($s = getimagesize($tmb)) !== false) {
                     $result = true;
                 }
             } catch (Exception $e) {
             }
         }
         if (!$result) {
             file_exists($tmb) && unlink($tmb);
             return false;
         }
         $result = false;
     }
     /* If image smaller or equal thumbnail size - just fitting to thumbnail square */
     if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) {
         $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
     } else {
         if ($this->options['tmbCrop']) {
             $result = $tmb;
             /* Resize and crop if image bigger than thumbnail */
             if (!($s[0] > $tmbSize && $s[1] <= $tmbSize || $s[0] <= $tmbSize && $s[1] > $tmbSize) || $s[0] > $tmbSize && $s[1] > $tmbSize) {
                 $result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
//.........这里部分代码省略.........
开发者ID:bigbrush,项目名称:yii2-big,代码行数:101,代码来源:elFinderVolumeDriver.class.php


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