アップロードされた画像を受け取るこの PHP スクリプトがあります。アップロードされた画像は一時フォルダーに保存され、このスクリプトは画像を再サンプリングして正しいフォルダーに保存します。ユーザーは、JPG、PNG、または GIF ファイルのいずれかをアップロードできます。ただし、このスクリプトは JPG ファイルのみに対応しています。
このスクリプトを変更して、透過性を失わずに PNG と GIF の両方のサイズを変更するにはどうすればよいですか?
$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$src = $_POST['n'];
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
$new_src = str_replace('/temp','',$_POST['n']);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
imagejpeg($dst_r,$new_src,$jpeg_quality);