Admin Login

Login to manage blogs.

Back to Blog

Forgot Password

Send reset link to admin@eduloomeducation.com

function optimize_image($src, $dest, $maxW = 256, $maxH = 256) { if (!file_exists($src)) return false; $info = getimagesize($src); if (!$info) return false; $mime = isset($info['mime']) ? $info['mime'] : ''; $create = null; $save = null; $ext = 'png'; if ($mime === 'image/jpeg' || $mime === 'image/jpg') { $create = 'imagecreatefromjpeg'; $save = function($im,$p){ imagejpeg($im,$p,85); }; $ext='jpg'; } elseif ($mime === 'image/png') { $create = 'imagecreatefrompng'; $save = function($im,$p){ imagesavealpha($im,true); imagepng($im,$p,6); }; $ext='png'; } elseif ($mime === 'image/webp' && function_exists('imagecreatefromwebp')) { $create = 'imagecreatefromwebp'; $save = function($im,$p){ imagewebp($im,$p,85); }; $ext='webp'; } if (!$create) return false; $srcIm = @$create($src); if (!$srcIm) return false; $sw = imagesx($srcIm); $sh = imagesy($srcIm); $scale = min($maxW / $sw, $maxH / $sh, 1); $tw = (int)floor($sw * $scale); $th = (int)floor($sh * $scale); $dstIm = imagecreatetruecolor($tw, $th); if ($mime === 'image/png' || $mime === 'image/webp') { imagealphablending($dstIm,false); imagesavealpha($dstIm,true); } imagecopyresampled($dstIm, $srcIm, 0, 0, 0, 0, $tw, $th, $sw, $sh); @$save($dstIm, $dest); imagedestroy($srcIm); imagedestroy($dstIm); return file_exists($dest); }