I'm using a script that helps users to upload their profile images then to crop them to choose the convenient position I have a problem with PNG & GIF images they aren't shown This is the crop file code please modify it in order to make it able to show the PNG , JPF and GIF images
<?php
sleep(1);
$url = $_GET['url'];
$type = $_GET['type'];
if ($type='jpg') {
if(file_exists($url) AND preg_match('/^[a-z0-9\/_\-.]+$/i',$url)){
$width = (isset($_GET['width']) AND preg_match('/^[0-9]{2,}$/', $_GET['width'])) ? $_GET['width'] : 300;
$height = (isset($_GET['height']) AND preg_match('/^[0-9]{2,}$/', $_GET['height'])) ? $_GET['height'] : 300;
$left = (isset($_GET['left']) AND is_numeric($_GET['left'])) ? $_GET['left'] : 0;
$top = (isset($_GET['top']) AND is_numeric($_GET['top'])) ? $_GET['top'] : 0;
header ("Content-type: image/jpg");
$src = @imagecreatefromjpeg($url);
$im = @imagecreatetruecolor($width, $height);
imagecopy($im,$src,0,0,-$left,-$top,$width,$height);
imagejpeg($im,"",300);
imagedestroy($im);}}
elseif ($type='png') {
if(file_exists($url) AND preg_match('/^[a-z0-9\/_\-.]+$/i',$url)){
$width = (isset($_GET['width']) AND preg_match('/^[0-9]{2,}$/', $_GET['width'])) ? $_GET['width'] : 300;
$height = (isset($_GET['height']) AND preg_match('/^[0-9]{2,}$/', $_GET['height'])) ? $_GET['height'] : 300;
$left = (isset($_GET['left']) AND is_numeric($_GET['left'])) ? $_GET['left'] : 0;
$top = (isset($_GET['top']) AND is_numeric($_GET['top'])) ? $_GET['top'] : 0;
header ("Content-type: image/png");
$src = @imagecreatefrompng($url);
$im = @imagecreatetruecolor($width, $height);
imagecopy($im,$src,0,0,-$left,-$top,$width,$height);
imagepng($im,"",300);
imagedestroy($im);
}
}
?>