缩略图支持webp

pull/18/head
icret 2022-01-05 01:19:42 +08:00
parent 341cf72709
commit 7e581563a7
1 changed files with 88 additions and 57 deletions

View File

@ -18,7 +18,8 @@
// namespace Thumb; // namespace Thumb;
// https://github.com/aileshe/Thumb // https://github.com/aileshe/Thumb
class Thumb{ class Thumb
{
private static $img_type; # 原图片格式 private static $img_type; # 原图片格式
/** /**
@ -28,7 +29,8 @@ class Thumb{
* @param String $height 预生成缩略图高度 * @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中 * @param String $valign [middle|top|bottom],默认 居中
*/ */
public static function show($filename, $width, $height, $valign='middle'){ public static function show($filename, $width, $height, $valign = 'middle')
{
$thumb = self::make($filename, $width, $height, $valign); $thumb = self::make($filename, $width, $height, $valign);
header('Content-Type:image/' . self::$img_type); header('Content-Type:image/' . self::$img_type);
echo $thumb; echo $thumb;
@ -42,7 +44,8 @@ class Thumb{
* @param String $height 预生成缩略图高度 * @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中 * @param String $valign [middle|top|bottom],默认 居中
*/ */
public static function out($filename, $output, $width, $height, $valign='middle'){ public static function out($filename, $output, $width, $height, $valign = 'middle')
{
$thumb = self::make($filename, $width, $height, $valign); $thumb = self::make($filename, $width, $height, $valign);
$fh = fopen($output, 'wb'); # 二进制文件 $fh = fopen($output, 'wb'); # 二进制文件
fwrite($fh, $thumb); fwrite($fh, $thumb);
@ -57,7 +60,8 @@ class Thumb{
* @param String $height 预生成缩略图高度 * @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中 * @param String $valign [middle|top|bottom],默认 居中
*/ */
public static function showOut($filename, $output, $width, $height, $valign='middle'){ public static function showOut($filename, $output, $width, $height, $valign = 'middle')
{
$thumb = self::make($filename, $width, $height, $valign); $thumb = self::make($filename, $width, $height, $valign);
$fh = fopen($output, 'wb'); # 二进制文件 $fh = fopen($output, 'wb'); # 二进制文件
fwrite($fh, $thumb); fwrite($fh, $thumb);
@ -74,9 +78,36 @@ class Thumb{
* @param String $valign [middle|top|bottom],默认 居中 * @param String $valign [middle|top|bottom],默认 居中
* @return FileString 原始图象流 * @return FileString 原始图象流
*/ */
private static function make($filename,$width,$height,$valign='middle'){ private static function make($filename, $width, $height, $valign = 'middle')
{
ini_set('gd.jpeg_ignore_warning', true); ini_set('gd.jpeg_ignore_warning', true);
$filetype=array(1=>'gif',2=>'jpeg',3=>'png'); /**
* 2022-1-4 23:34:37 EasyImage更改图像类型判断
* getimagesize索引2给出的是图像的类型返回的是数字
* 1 = GIF2 = JPG3 = PNG4 = SWF5 = PSD6 = BMP7 = TIFF(intel byte order)8 = TIFF(motorola byte order)
* 9 = JPC10 = JP211 = JPX12 = JB213 = SWC14 = IFF15 = WBMP16 = XBM
*/
$filetype = array(
0 => 'unknown',
1 => 'gif',
2 => 'jpeg',
3 => 'png',
4 => 'swf',
5 => 'psd',
6 => 'bmp',
7 => 'tif_ii',
8 => 'tiff_mm',
9 => 'jpc',
10 => 'jp2',
11 => 'jpx',
12 => 'jb2',
13 => 'swc',
14 => 'iff',
15 => 'wbmp',
16 => 'xbm',
17 => 'ico',
18 => 'webp'
);
# 获取图片信息 # 获取图片信息
$imginfo = getimagesize($filename); $imginfo = getimagesize($filename);
$img_w = $imginfo[0]; $img_w = $imginfo[0];