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


PHP Thumbnail::imageCreate方法代码示例

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


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

示例1: render

 /**
  * Draw thumbnail result to resource.
  *
  * @param  mixed $input Destination image, a filename or an image string data or a GD image resource
  * @param  array $options Thumbnail options
  *
  * @return boolean TRUE on success or FALSE on failure.
  * @access public
  * @see    Thumbnail::output()
  */
 function render($input, $options = array())
 {
     // Create the source image
     $sourceImage = Thumbnail::imageCreate($input);
     if (!is_resource($sourceImage)) {
         user_error('Invalid image resource', E_USER_NOTICE);
         return false;
     }
     $sourceWidth = imagesx($sourceImage);
     $sourceHeight = imagesy($sourceImage);
     // Set default options
     static $defOptions = array('width' => 150, 'height' => 150, 'method' => THUMBNAIL_METHOD_SCALE_MAX, 'percent' => 0, 'halign' => THUMBNAIL_ALIGN_CENTER, 'valign' => THUMBNAIL_ALIGN_CENTER);
     foreach ($defOptions as $k => $v) {
         if (!isset($options[$k])) {
             $options[$k] = $v;
         }
     }
     // Estimate a rectangular portion of the source image and a size of the target image
     if ($options['method'] == THUMBNAIL_METHOD_CROP) {
         if ($options['percent']) {
             $W = floor($options['percent'] * $sourceWidth);
             $H = floor($options['percent'] * $sourceHeight);
         } else {
             $W = $options['width'];
             $H = $options['height'];
         }
         $width = $W;
         $height = $H;
         $Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
         $X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
     } else {
         $X = 0;
         $Y = 0;
         $W = $sourceWidth;
         $H = $sourceHeight;
         if ($options['percent']) {
             $width = floor($options['percent'] * $W);
             $height = floor($options['percent'] * $H);
         } else {
             $width = $options['width'];
             $height = $options['height'];
             if ($options['method'] == THUMBNAIL_METHOD_SCALE_MIN) {
                 $Ww = $W / $width;
                 $Hh = $H / $height;
                 if ($Ww > $Hh) {
                     $W = floor($width * $Hh);
                     $X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
                 } else {
                     $H = floor($height * $Ww);
                     $Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
                 }
             } else {
                 if ($H > $W) {
                     $width = floor($height / $H * $W);
                 } else {
                     $height = floor($width / $W * $H);
                 }
             }
         }
     }
     // Create the target image
     if (function_exists('imagecreatetruecolor')) {
         $targetImage = imagecreatetruecolor($width, $height);
     } else {
         $targetImage = imagecreate($width, $height);
     }
     if (!is_resource($targetImage)) {
         user_error('Cannot initialize new GD image stream', E_USER_NOTICE);
         return false;
     }
     // Copy the source image to the target image
     if ($options['method'] == THUMBNAIL_METHOD_CROP) {
         $result = imagecopy($targetImage, $sourceImage, 0, 0, $X, $Y, $W, $H);
     } elseif (function_exists('imagecopyresampled')) {
         $result = imagecopyresampled($targetImage, $sourceImage, 0, 0, $X, $Y, $width, $height, $W, $H);
     } else {
         $result = imagecopyresized($targetImage, $sourceImage, 0, 0, $X, $Y, $width, $height, $W, $H);
     }
     if (!$result) {
         user_error('Cannot resize image', E_USER_NOTICE);
         return false;
     }
     // Free a memory from the source image
     imagedestroy($sourceImage);
     // Save the resulting thumbnail
     return $targetImage;
 }
开发者ID:saity74,项目名称:joomla-catalogue-component,代码行数:97,代码来源:thumbnail.php

示例2: render

 /**
  * Процесс создания копии изображения с заданными параметрами
  *
  * @param  mixed   $input    Имя файла, изображение-строка или GD-resource
  * @param  array   $options  Массив настроек
  *
  * @return resource|boolean TRUE или FALSE.
  * @access public
  * @see    Thumbnail::output()
  */
 public static function render($input, $options = array())
 {
     // Создаем ресурс
     $sourceImage = Thumbnail::imageCreate($input);
     if (!is_resource($sourceImage)) {
         throw new joosImageLibrariesException('Invalid image resource');
     }
     $sourceWidth = imagesx($sourceImage);
     $sourceHeight = imagesy($sourceImage);
     // Устанавливаем настройки по-умолчанию
     static $defOptions = array('width' => 150, 'height' => 150, 'method' => THUMBNAIL_METHOD_SCALE_MAX, 'percent' => 0, 'halign' => THUMBNAIL_ALIGN_CENTER, 'valign' => THUMBNAIL_ALIGN_CENTER, 'check_size' => 0, 'resize' => 1);
     foreach ($defOptions as $k => $v) {
         if (!isset($options[$k])) {
             $options[$k] = $v;
         }
     }
     $resize = 1;
     if ($options['check_size'] == 1 && $sourceWidth <= $options['width'] && $sourceHeight <= $options['height'] || $options['resize'] == 0) {
         $resize = 0;
     }
     if ($resize) {
         // Estimate a rectangular portion of the source image and a size of the target image
         if ($options['method'] == THUMBNAIL_METHOD_CROP) {
             if ($options['percent']) {
                 $W = floor($options['percent'] * $sourceWidth);
                 $H = floor($options['percent'] * $sourceHeight);
             } else {
                 $W = $options['width'];
                 $H = $options['height'];
             }
             $width = $W;
             $height = $H;
             $Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
             $X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
         } else {
             $X = 0;
             $Y = 0;
             $W = $sourceWidth;
             $H = $sourceHeight;
             if ($options['percent']) {
                 $width = floor($options['percent'] * $W);
                 $height = floor($options['percent'] * $H);
             } else {
                 $width = $options['width'];
                 $height = $options['height'];
                 if ($options['method'] == THUMBNAIL_METHOD_SCALE_MIN) {
                     $Ww = $W / $width;
                     $Hh = $H / $height;
                     if ($Ww > $Hh) {
                         $W = floor($width * $Hh);
                         $X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
                     } else {
                         $H = floor($height * $Ww);
                         $Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
                     }
                 } else {
                     if ($H > $W) {
                         $width = floor($height / $H * $W);
                     } else {
                         $height = floor($width / $W * $H);
                     }
                 }
             }
         }
     } else {
         $W = $sourceWidth;
         $H = $sourceHeight;
         $width = $sourceWidth;
         $height = $sourceHeight;
         $X = 0;
         $Y = 0;
     }
     // Create the target image
     if (function_exists('imagecreatetruecolor')) {
         $targetImage = imagecreatetruecolor($width, $height);
     } else {
         $targetImage = imagecreate($width, $height);
     }
     if (!is_resource($targetImage)) {
         throw new joosImageLibrariesException('Cannot initialize new GD image stream', E_USER_NOTICE);
         return false;
     }
     if ($options['method'] == THUMBNAIL_METHOD_CROP && isset($options['x']) && isset($options['y'])) {
         $X = $options['x'];
         $Y = $options['y'];
     }
     // Copy the source image to the target image
     if ($options['method'] == THUMBNAIL_METHOD_CROP) {
         $result = imagecopy($targetImage, $sourceImage, 0, 0, $X, $Y, $W, $H);
     } elseif (function_exists('imagecopyresampled')) {
//.........这里部分代码省略.........
开发者ID:joostina,项目名称:joostina,代码行数:101,代码来源:image.php


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