0

画像を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");
}

私は何を間違っていますか?
または
それを行う方法についてより良いアイデアはありますか?

前もって感謝します

4

1 に答える 1

1

簡単なグーグルで、この質問をstackoverflowで取得できます。画像を変換するための簡単な関数が提供されます。

正しい jpg ヘッダーについては、この回答を見つけました。

2つを組み合わせると仕事をするはずです

于 2013-05-15T12:45:21.233 に答える