请帮助我解决当前的功能,以使其将任何其他图像类型成功转换为正确的jpg图像类型。
这是我的职能
function resize_image($oldimage_name, $new_image_name){
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = 250; $height = 250;
$im = imagecreatetruecolor($width, $height);
$img_src = imagecreatefromjpeg($oldimage_name);
imagealphablending($img_src, false);
imagesavelalpha($img_src, true);
imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
imagejpeg($im, $new_image_name, 90);
imagedestroy($im);
unlink($oldimage_name);
return true;
}
感谢您的时间和事前帮助
如果不是jpg,则会失败。请改用imagecreatefromstring()。这可以猜出真正的格式。
替换这样的代码
$img_src = imagecreatefromstring(file_get_contents($oldimage_name));