GD LIB如何将每个上传的图像成功转换为jpg类型?

问题描述 投票:0回答:1

请帮助我解决当前的功能,以使其将任何其他图像类型成功转换为正确的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;
}

感谢您的时间和事前帮助

php function image-resizing gdlib
1个回答
0
投票

如果不是jpg,则会失败。请改用imagecreatefromstring()。这可以猜出真正的格式。

替换这样的代码

$img_src = imagecreatefromstring(file_get_contents($oldimage_name));
© www.soinside.com 2019 - 2024. All rights reserved.