I am creating a image convert function. File extension not changing eg oldfile.png
out newfile.png
. But it should change the extension after file convert eg newfile.jpg
right?
function convertimg($target, $new, $ext, $converto) {
if ($ext['mime'] == 'image/jpeg') {
$img = imagecreatefromjpeg($target);
} elseif ($ext['mime'] == 'image/png') {
$img = imagecreatefrompng($target);
} elseif ($ext['mime'] == 'image/gif') {
$img = imagecreatefromgif($target);
}
$ictc = imagecreatetruecolor($ext[0], $ext[1]);
imagecopyresampled($ictc, $img, 0, 0, 0, 0, $ext[0], $ext[1], $ext[0], $ext[1]);
ob_start();
header("Content-type: " . $converto);
if ($converto == 'image/jpeg') {
imagejpeg($ictc, $new, 84);
} elseif ($converto == 'image/png') {
imagepng($ictc, $new, 84);
} elseif ($converto == 'image/gif') {
imagegif($ictc, $new, 84);
}
ob_get_clean();
imagedestroy($ictc);
}
No it should not, since you supply the new file name, it could be anything.
So if you are converting, you must also supply a new extendsion. The only thing imagegpeg does is saving raw image to a jpeg format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.