function scaleImage($storage, $folder, $filename, $width) {
$ext = strrchr($storage . $folder . $filename, ".");
switch ($ext){
case '.jpg':
$originPicture = imagecreatefromjpeg($storage . $folder . $filename);
break;
case '.png':
$originPicture = imagecreatefrompng($storage . $folder . $filename);
break;
default:
return false;
}
$originW = imagesx($originPicture);
$originH = imagesy($originPicture);
$targetW = $width;
$targetH = intval($originH / $originW * $width);
$targetPicture = imagecreatetruecolor($targetW, $targetH);
// Adjust PNG Transparent
imagecopyresized($targetPicture, $originPicture, 0, 0, 0, 0, $targetW, $targetH, $originW, $originH);
if($ext == '.jpg') {
imagejpeg($targetPicture, $storage . $folder . $width . 'x/' . $filename, 85);
} else {
imagepng($targetPicture, $storage . $folder . $width . 'x/' . $filename, 8);
}
return true;
}
Scale a previously saved image and create a scaled copy in a new folder. Scale is based on width.
Currently only works with JPG and PNG file formats
Currently only works with JPG and PNG file formats
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.