我正在用PHP开发一个网站,该网站允许用户上传图像,然后让他决定图像应如何使用jQuery-
PHP整数选择要作为图片的区域,然后单击“裁剪”按钮将其裁剪并保存。
我面临的问题是并非所有图像类型都适合裁剪和保存,因此我注意到,将图像转换为JPG然后让用户裁剪的简单解决方案是因为这是在其中轻松实现的方法JPG格式。
我该怎么办?
这是解决图像类型问题的最佳解决方案吗?
编辑:
我正在使用此代码来裁剪图像,并且它不是以PNG格式出现,并且仅限于3 ext。
$path_parts = pathinfo("../images/DVDs/".$_POST['logo_file']);
if ($path_parts['extension'] == "png") {
$src = imagecreatefrompng("../images/DVDs/".$_POST['logo_file']);
$tmp = imagecreatetruecolor(350, 494);
imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],350,494,$_POST['w'],$_POST['h']);
imagepng($tmp, "../images/DVDs/$filename".'t_'.$_POST['logo_file'],100);
} else if ($path_parts['extension'] == "jpg" || $path_parts['extension'] == "jpeg") {
$src = imagecreatefromjpeg("../images/DVDs/".$_POST['logo_file']);
$tmp = imagecreatetruecolor(350, 494);
imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],350,494,$_POST['w'],$_POST['h']);
imagejpeg($tmp, "../images/DVDs/$filename".'t_'.$_POST['logo_file'],100);
} else if ($path_parts['extension'] == "gif") {
$src = imagecreatefromgif("../images/DVDs/".$_POST['logo_file']);
$tmp = imagecreatetruecolor(350, 494);
imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],350,494,$_POST['w'],$_POST['h']);
imagegif($tmp, "../images/DVDs/$filename".'t_'.$_POST['logo_file'],100);
}
我想将图像转换为JPG格式,因为它最容易转换而没有任何问题。