function thumbnail($upfiledir, $src, $tName, $tw = '', $th = '', $scale = true, $tDir = "thumb") { global $iCMS; $R = array(); $tw = empty($tw) ? $iCMS->config['thumbwidth'] : (int) $tw; $th = empty($th) ? $iCMS->config['thumbhight'] : (int) $th; if ($tw && $th) { list($width, $height, $type) = @getimagesize($src); if ($width < 1 && $height < 1) { $R['width'] = $tw; $R['height'] = $th; $R['src'] = $src; return $R; } if ($width > $tw || $height > $th) { $R['src'] = $upfiledir . $tDir . "/" . $tName . '_' . $tw . 'x' . $th . '.' . substr(strrchr($src, "."), 1); if (in_array('Gmagick', get_declared_classes())) { $image = new Gmagick(); $image->readImage($src); $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $image->getImageWidth(), "h" => $image->getImageHeight())); $image->resizeImage($im['w'], $im['h'], null, 1); $image->cropImage($tw, $th, 0, 0); //$image->thumbnailImage($gm_w,$gm_h); FS::mkdir($upfiledir . $tDir); $image->writeImage($R['src']); $image->destroy(); } else { $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $width, "h" => $height), $scale); $R['width'] = $im['w']; $R['height'] = $im['h']; $res = self::imagecreate($type, $src); if ($res) { $thumb = imagecreatetruecolor($im['w'], $im['h']); imagecopyresampled($thumb, $res, 0, 0, 0, 0, $im['w'], $im['h'], $width, $height); //PHP_VERSION != '4.3.2' && self::UnsharpMask($thumb); FS::mkdir($upfiledir . $tDir); self::image($thumb, $type, $R['src']); } else { $R['src'] = $src; } } } else { $R['width'] = $width; $R['height'] = $height; $R['src'] = $src; } return $R; } }
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($Call['Current Image']['Resample']) && !empty($Call['Current Image']['Data'])) { try { $GImage = new Gmagick(); $GImage->readimageblob($Call['Current Image']['Data']); if (isset($Call['Current Image']['Height'])) { } else { $Call['Current Image']['Height'] = ceil($Call['Current Image']['Width'] / $GImage->getimagewidth() * $GImage->getimageheight()); } if (isset($Call['Current Image']['Width'])) { } else { $Call['Current Image']['Width'] = ceil($Call['Current Image']['Height'] / $GImage->getimageheight() * $GImage->getimagewidth()); } $GImage->resizeImage($Call['Current Image']['Width'], $Call['Current Image']['Height'], Gmagick::FILTER_LANCZOS, 1); $Call['Current Image']['Data'] = $GImage->getImageBlob(); } catch (Exception $e) { F::Log($e->getMessage(), LOG_ERR); } } return $Call; });
/** * 生成缩略图 * @param [type] $path [原图路径] * @param integer $tw [缩略图宽度] * @param integer $th [缩略图高度] * @return [image] [缩略图资源] */ public static function make($path, $tw = 1, $th = 1) { strpos($path, '..') === false or exit('What are you doing?'); $srcPath = iPHP_RES_PAHT . $path; $thumbPath = $srcPath . '_' . $tw . 'x' . $th . '.jpg'; if (empty($path) || !self::exists($srcPath)) { return self::blank(); } iPHP_RES_CACHE && (self::$srcData = self::cache($thumbPath, 'get')); if (empty(self::$srcData)) { $gmagick = new Gmagick(); $gmagick->readImage($srcPath); $scale = array("tw" => $tw, "th" => $th, "w" => $gmagick->getImageWidth(), "h" => $gmagick->getImageHeight()); if ($tw > 0 && $th > 0) { $im = self::scale($scale); $gmagick->resizeImage($im['w'], $im['h'], null, 1); $x = $y = 0; $im['w'] > $im['tw'] && ($x = ceil(($im['w'] - $im['tw']) / 3)); $im['h'] > $im['th'] && ($y = ceil(($im['h'] - $im['th']) / 3)); $gmagick->cropImage($tw, $th, $x, $y); } else { empty($scale['th']) && ($scale['th'] = 9999999); $im = self::bitScale($scale); $gmagick->resizeImage($im['w'], $im['h'], null, 1); } header('X-Thumb-Cache: MAKE-' . $_SERVER['REQUEST_TIME']); self::$srcData = $gmagick->current(); iPHP_RES_CACHE && self::cache($thumbPath, self::$srcData); } }
break; case 3: $res = imagecreatefrompng($src); break; } return $res; } } } if (fsexists($src)) { $image = new Gmagick(); $image->readImage($src); $scale = array("tw" => $tw, "th" => $th, "w" => $image->getImageWidth(), "h" => $image->getImageHeight()); if ($tw > 0 && $th > 0) { $im = scale($scale); $image->resizeImage($im['w'], $im['h'], null, 1); $x = $y = 0; $im['w'] > $im['tw'] && ($x = ceil(($im['w'] - $im['tw']) / 3)); $im['h'] > $im['th'] && ($y = ceil(($im['h'] - $im['th']) / 3)); $image->cropImage($tw, $th, $x, $y); } else { empty($scale['th']) && ($scale['th'] = 9999999); $im = bitscale($scale); $image->resizeImage($im['w'], $im['h'], null, 1); } $expires = 31536000; header("Cache-Control: maxage=" . $expires); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME']) . ' GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $expires) . ' GMT'); $srcData = $image->current(); } else {
public static function thumbnail($src, $tw = "0", $th = "0", $scale = true) { if (!self::$config['thumb']['enable']) { return; } $rs = array(); $tw = empty($tw) ? self::$config['thumb']['width'] : (int) $tw; $th = empty($th) ? self::$config['thumb']['height'] : (int) $th; if ($tw && $th) { list($width, $height, $type) = getimagesize($src); if ($width < 1 && $height < 1) { $rs['width'] = $tw; $rs['height'] = $th; $rs['src'] = $src; return $rs; } if ($width > $tw || $height > $th) { $rs['src'] = $src . '_' . $tw . 'x' . $th . '.jpg'; if (in_array('Gmagick', get_declared_classes())) { $image = new Gmagick(); $image->readImage($src); $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $image->getImageWidth(), "h" => $image->getImageHeight())); $image->resizeImage($im['w'], $im['h'], null, 1); $image->cropImage($tw, $th, 0, 0); //$image->thumbnailImage($gm_w,$gm_h); $image->writeImage($rs['src']); $image->destroy(); } else { $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $width, "h" => $height), $scale); $ret = self::imagecreate($type, $src); $rs['width'] = $im['w']; $rs['height'] = $im['h']; if ($ret) { $thumb = imagecreatetruecolor($im['w'], $im['h']); imagecopyresampled($thumb, $ret, 0, 0, 0, 0, $im['w'], $im['h'], $width, $height); self::image($thumb, $type, $rs['src']); } else { $rs['src'] = $src; } } } else { $rs['src'] = $src; $rs['width'] = $width; $rs['height'] = $height; } return $rs; } }