Always use JPEG for Thumbnails

This commit is contained in:
seiichiro 2022-08-10 21:22:40 +02:00
parent d54027beeb
commit 54f9593e51

View file

@ -11,22 +11,15 @@ class thumb {
const IMAGE_HANDLERS = [
IMAGETYPE_JPEG => [
'load' => 'imagecreatefromjpeg',
'save' => 'imagejpeg',
'quality' => 100
],
IMAGETYPE_PNG => [
'load' => 'imagecreatefrompng',
'save' => 'imagepng',
'quality' => 0
],
IMAGETYPE_GIF => [
'load' => 'imagecreatefromgif',
'save' => 'imagegif',
],
IMAGETYPE_WEBP => [
'load' => 'imagecreatefromwebp',
'save' => 'imagecreatewebp',
'quality' => 90
]
];
@ -40,10 +33,8 @@ class thumb {
public function get_thumb($iname) {
$src = $this->imagedir.$iname;
$ext = pathinfo($iname, PATHINFO_EXTENSION);
$dstname = hash('sha256', $src);
$dstpath = $this->thumbdir.$dstname.'.'.$ext;
$dstpath = $this->thumbdir.$dstname.'.jpg';
if (!file_exists($dstpath)) {
$type = exif_imagetype($src);
@ -78,15 +69,11 @@ class thumb {
}
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $width, $height, $srcwidth, $srcheight);
if ($type != IMAGETYPE_GIF) {
call_user_func(self::IMAGE_HANDLERS[$type]['save'],$thumbnail,$dstpath,self::IMAGE_HANDLERS[$type]['quality']);
} else {
call_user_func(self::IMAGE_HANDLERS[$type]['save'],$thumbnail,$dstpath);
}
call_user_func('imagejpeg',$thumbnail,$dstpath,100);
imagedestroy($image);
imagedestroy($thumbnail);
}
return $this->thumburl.$dstname.'.'.$ext;
return $this->thumburl.$dstname.'.jpg';
}
}