I am developing a website in PHP that let the user to upload images and then let him to decide how the image should be using jQuery - PHP integeration to select the area that wanted to be the picture and then click the crop button to crop it and save it.
The problem that I am facing is that not all images type are good to crop and save so I noticed that the easy solution for it to convert the image to JPG and then let the user to crop it because it's the easy way to do it in JPG format.
How I can do it?
Is this the best solution for images types problem?
EDIT:
I am using this code to crop images and it's not wroking in PNG format and also limited to 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);
}
I want to convert images to JPG format because it's the easiest to convert without any problem.
See Question&Answers more detail:
os