Currently changing all images to webp - webp images are a lot smaller
This uses the gd extension and will save loads of space. As far as i know most browsers support webp.
I added check if gd added or use php copy
where ever copy is we just will add new function passing source and destination so edits are small

Example For TMDB posters under saveimage i used this - halving image sizes
This uses the gd extension and will save loads of space. As far as i know most browsers support webp.
I added check if gd added or use php copy
where ever copy is we just will add new function passing source and destination so edits are small
function copyImage($source, $destination, $redirect = URLROOT)
{
if (extension_loaded('gd')) {
// compress size max 100
$compression_quality = 25;
// set type
$type = substr($destination, -3);
$jpeg = substr($destination, -4);
// set destination
$new_destination = substr($destination, 0, -3) . 'webp';
if ($type == 'png') {
$image = imagecreatefrompng($source);
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
} elseif ($type == 'jpg') {
$image = imagecreatefromjpeg($source);
} elseif ($type == 'gif') {
$image = imagecreatefromgif($source);
imagepalettetotruecolor($image);
} elseif ($jpeg == 'jpeg') {
$image = imagecreatefromjpeg($source);
$new_destination = substr($destination, 0, -4) . 'webp';
} else {
Redirect::autolink($redirect, sprintf(Lang::T("Strange Image Type")));
}
// convert image
$result = imagewebp($image, $new_destination, $compression_quality);
// check result
if (false === $result) {
Redirect::autolink($redirect, sprintf(Lang::T("No Image Result")));
}
// destroy temp
imagedestroy($image);
return $new_destination;
} else {
$copy = copy($source, $destination);
if (!$copy) {
Redirect::autolink($redirect, sprintf(Lang::T("IMAGE_UPLOAD_FAILED")));
}
return $destination;
}
}
Example For TMDB posters under saveimage i used this - halving image sizes
if (extension_loaded('gd')) {
copyImage(UPLOADDIR . "/tmdb/film/$id_tmdb.jpg", UPLOADDIR . "/tmdb/film/$id_tmdb.jpg");
unlink(UPLOADDIR . "/tmdb/film/$id_tmdb.jpg");
unlink(CACHE . "/tmdb/film/$id_tmdb.cache");
$image = "$id_tmdb.webp";
}
Last edited by M-jay
on 2022-10-06 08:40:52
on 2022-10-06 08:40:52