Пример #1
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 {
    //1x1.gif
    $srcData = 'R0lGODlhAQABAIAAAAAAAP///yH5BAEHAAEALAAAAAABAAEAAAICTAEAOw==';
    //nopic.gif
    $srcData = 'R0lGODlhyADIAKIAAMzMzP///+bm5vb29tXV1d3d3e7u7gAAACH5BAAHAP8ALAAAAADIAMgAAAP/
	SLrc/jDKSau9OOs9g/9gKI5kaZ5oqq5s676kAs90bd94bsp67//AoIonLBqPSBYxyWw6g8undEpVEqrYrBYU3Xq/
	xy54TM6Jy+h066xuu0fst9wdn9vL9bvem9/7q31/gk6Bg4ZhV4eKVIWLjjqNj5I1kZOWLpWXmimZm54xiZ+iM52j
	o6Wmn6ipm6usl66vk7Gyj7S1i7e4h7q7g72+f8DBe8PEd8bHc8nKb8zNbc/QadLTeKHWp9jZqtvcrd7fsOHis+Tl
	tufouerrvO3uv/DxwvM9Avj5+vv8/f7/AAMKHEjwHyF7OgSgU9ikWgiG4iAmcQhCIjeLiJxgtLax/wjFDx2hhYSC
	MMdIZSd/fPSQkljLHisDvPQ100xJHC0L6NzJs6fPn0CDCh1KFGiKmjhinizKtKnTp01PIL2h1ATUq1izMjUx1UbV
	ElrDig3L9aBGsGPTqo1KoiulmzdCrp1L92cJtzS+jqjLt+5ds03k9h2c9m9DuDYEE16c1TATvSIKg2AseQReUohr
	KMZqlbJWxxMz0wiJ72oKz43bAmZCumC+Fq5jy+4HGgnkh65hzN4tu3bGwHcJDpjBuzhB30ZuVxw4YDhx49D9Ifco
	mnhwgM2zj47O/bXqw2fbYs9O/nl32QbSG/BueXWS1v3Iy29u/rxA9fjZi7gMQznI+P/zBajbP/ipN9t6AhSoYHrT
	CeEfSzLhE+CE2n1A31H9LGhgbBou2CBJ4VkmAIUklmfhCvt0mB4/uGWoIoPfPVadbiWkV+KNJjqHQood6iOePi+q
	VxZ4wJGA45ECYhgkjCaQt+SQMoYoApJUypfCkgakUKKQWUIZmpQhVCmmiSa8WAIAAFiI41HuIRHSmHDqWKaHIqBpp
Пример #2
0
 /**
  * 生成缩略图
  * @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);
     }
 }