画像をJPGとしてエクスポートするオプションをユーザーに提供し、png画像を保存
しました。そのため、PHPスクリプトを作成しました。
pngは正常に変換されています..
しかし、jpg画像をダウンロードして画像ビューアで開こうとすると、表示が壊れます。
私のphpコード:
PNG から JPG への変換
$input_file = 'images/image1364926178.png';
$filename = time().'.jpg';
$output_file = 'images/'.$filename;
$input = imagecreatefrompng($input_file);
if($input){
list($width, $height) = getimagesize($input_file);
$output = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($output, 255, 255, 255);
imagefilledrectangle($output, 0, 0, $width, $height, $white);
imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
imagejpeg($output,$output_file);
}
jpg 画像をダウンロードするスクリプト
$Image_file_name = '/images/'.$filename;
$filedetail = getimagesize($filename);
$mimetype = $filedetail['mime'];
if (file_exists($filename)) {
@ob_end_clean();
header('Content-Description: File Transfer');
header('Content-Type: '.$mimetype);
header('Content-Disposition: attachment; filename='.basename($filename));
header("Content-Transfer-Encoding: binary");
header('Accept-Ranges: bytes');
header('Cache-Control: private');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
私は何を間違っていますか?
または
それを行う方法についてより良いアイデアはありますか?
前もって感謝します