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


PHP Thumbnail::dump方法代碼示例

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


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

示例1: imageGenerator

 /**
  * Image generator.
  *
  * @param string $imageFile     Image name.
  * @param int    $maxSize       Max size.
  * @param string $newFileName   New generated file name.
  * @param int    $qualitat      Quality.
  * @param string $waterMark     Watermark.
  *
  * @return array   Image resolution.
  */
 public static function imageGenerator($imageFile, $maxSize, $newFileName, $qualitat, $waterMark = '')
 {
     if (!file_exists($imageFile)) {
         return false;
     }
     // Size setter.
     list($width, $height, $type) = getimagesize($imageFile);
     $larger = $width > $height ? $width : $height;
     $smaller = $width > $height ? $height : $width;
     if ($larger <= $maxSize) {
         $newLarger = $larger;
         $newSmaller = $smaller;
     } else {
         $multiplication = $maxSize / $larger;
         $newLarger = $maxSize;
         $newSmaller = $smaller * $multiplication;
     }
     $newWidth = $width > $height ? $newLarger : $newSmaller;
     $newHeight = $width > $height ? $newSmaller : $newLarger;
     switch ($type) {
         case 1:
             $kep = imagecreatefromgif($imageFile);
             break;
         case 2:
             $kep = imagecreatefromjpeg($imageFile);
             break;
         case 3:
             $kep = imagecreatefrompng($imageFile);
             break;
     }
     $ujkep = imagecreatetruecolor($newWidth, $newHeight);
     imagecopyresampled($ujkep, $kep, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     imagejpeg($ujkep, $newFileName, $qualitat);
     // Contructor and set source image file
     $thumb = new Thumbnail($newFileName);
     // [OPTIONAL] set maximun memory usage, default 32 MB ('32M'). (use '16M' or '32M' for litter images)
     $thumb->memory_limit = '64M';
     // [OPTIONAL] set maximun execution time, default 30 seconds ('30'). (use '60' for big images o slow server)
     $thumb->max_execution_time = 60;
     if ($waterMark != '') {
         // [OPTIONAL] set watermark source file, only PNG format [RECOMENDED ONLY WITH GD 2]
         $thumb->img_watermark = 'static/images/watermak/' . $waterMark;
     }
     // [OPTIONAL] set watermark vertical position, TOP | CENTER | BOTTOM
     $thumb->img_watermark_Valing = 'CENTER';
     // [OPTIONAL] set watermark horizonatal position, LEFT | CENTER | RIGHT
     $thumb->img_watermark_Haling = 'CENTER';
     $thumb->process();
     $newImage = $thumb->dump();
     imagejpeg($newImage, $newFileName, $qualitat);
     return array($newWidth, $newHeight);
 }
開發者ID:carriercomm,項目名稱:quantum-5,代碼行數:63,代碼來源:ImageHelper.php


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