$resized"); // si l'image resized n'existe pas, on la crée et on la traite if(!file_exists($resized)){ switch($ext){ case "jpg": $handle = imagecreatefromjpeg($original); break; case "gif": $handle = imagecreatefromgif($original); break; case "png": $handle = imagecreatefrompng($original); break; } $img_width = imagesx($handle); $img_height = imagesy($handle); $quality = 90; // on garde les proportions if($img_width > $width){ $width2 = $width; $height2 = $img_height / ($img_width / $width); } else { $width2 = $img_width; $height2 = $img_height; } if($height2 > $height){ $width = $width2 / ($height2 / $height); $height = $height; } else { $width = $width2; $height = $height2; } // creation de l'image $newhandle = imagecreatetruecolor($width, $height); if($ext == "png"){ imageAntiAlias($newhandle, true); imagealphablending($newhandle, true); imagesavealpha($newhandle, true); $transparent = imagecolorallocatealpha($newhandle, 255, 255, 255, 0); for($x=0; $x <= $img_width; $x++){ for($y=0; $y <= $img_height; $y++){ imageSetPixel($newhandle, $x, $y, $transparent); } } } imagecopyresampled($newhandle, $handle, 0, 0, 0, 0, round($width), round($height), $img_width, $img_height); // envoi et enregistrement de l'image switch($ext){ case "jpg": imagejpeg($newhandle, $resized, $quality); header("Content-type: image/jpeg"); imagejpeg($newhandle, null, $quality); break; case "gif": imagegif($newhandle, $resized, $quality); header("Content-type: image/gif"); imagegif($newhandle, null, $quality); break; case "png": imagepng($newhandle, $resized, $quality); header("Content-type: image/png"); imagepng($newhandle, null, $quality); break; } imagedestroy($handle); imagedestroy($newhandle); } // chargement de l'image $fichier = @fread(fopen($resized, "r"), filesize($resized)); // envoi de l'image switch($format){ case "jpg": header("Content-type: image/jpeg"); break; case "gif": header("Content-type: image/gif"); break; case "png": header("Content-type: image/png"); break; } print($fichier); ?>