-2

このコードを実行すると、次のエラーが発生します。

画像「http://siteprevue.net/flipit.php」はエラーが含まれているため表示できません。

って思ってるんだけど… もちろん表示できないし、画像じゃなくてURLだから… えっ!?

すべてが正常に実行されます。URL が画像であると考えるこの黒いページが表示されます。

これは、(一部の) 他の GD2 コード化されたページでも発生しますが、すべてではありません。

何が起こっているのか誰にも分かりませんか?

<?php
$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';
$new_img = '../../Uploads/Gallery/copy_bg_200.jpg';

$image = imagecreatefromjpeg($src);
$image = flip($image,1,0); // flips horizontal
//$image = flip($image,0,1); // flips vertical
//$image = flip($image,1,1); // flips both

header("Content-type: image/jpeg");
imagejpeg($image, $new_img, 80);
imagedestroy($image);

function flip($i,$h=1,$v=0) {
$width = imagesx($i);
$height = imagesy($i);
$temp = imagecreatetruecolor($width,$height);
imagecopy($temp,$i,0,0,0,0,$width,$height);
if ($h==1) {
for ($x=0 ; $x<$width ; $x++) {
imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);
}
imagecopy($temp,$i,0,0,0,0,$width,$height);
}
if($v==1) {
for ($x=0; $x<$height ; $x++) {
imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);
}
}
return $i;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org   /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
4

2 に答える 2

0

出力は jpeg であるため、最初に html は必要ありません。あなたは を逃しまし@@imagecreatefromjpeg。しかし、あなたの問題は、と一緒に機能しない出力ファイル名headerです。イメージは正常に作成されますが、エラーが発生します。

imagejpeg ファイル名

The path to save the file to. If not set or NULL, 
the raw image stream will be outputted directly.

ファイルを保存するか、 で印刷することができますheader。したがって、null を挿入する必要があります。これは私にとってはうまくいきますが、変更を保存しません:

<?php
$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';

$image = imagecreatefromjpeg($src);
$image = flip($image,1,0); // flips horizontal
//$image = flip($image,0,1); // flips vertical
//$image = flip($image,1,1); // flips both

header("Content-type: image/jpeg");
imagejpeg($image, null, 80);
imagedestroy($image);

function flip($i,$h=1,$v=0) {
    $width = imagesx($i);
    $height = imagesy($i);
    $temp = imagecreatetruecolor($width,$height);
    imagecopy($temp,$i,0,0,0,0,$width,$height);
    if ($h==1) {
        for ($x=0 ; $x<$width ; $x++) {
            imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);
        }
        imagecopy($temp,$i,0,0,0,0,$width,$height);
    }
    if($v==1) {
        for ($x=0; $x<$height ; $x++) {
            imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);
        }
    }
    return $i;
}

?>
于 2014-09-04T12:53:39.793 に答える