これは私が取り組んでいるthumnbailスクリプトであり、壊れた33バイトのイメージを作成してしまいます。私は問題がexif_imagetype ifステートメントにあると思うが、わからない。助けていただければ幸いです。PHPは破損したthumnbailを作成します
// Original image
$filename = 'images/T' . $neutralName;
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);
// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 10;
$top = 5;
// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 140;
$crop_height = 100;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
if ((exif_imagetype($_FILES['photo']['tmp_name'])) == IMAGETYPE_JPEG) {
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename, 100);
} else if ((exif_imagetype($_FILES["photo"]['tmp_name'])) == IMAGETYPE_GIF) {
$current_image = imagecreatefromgif($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagegif($canvas, $filename, 100);
} else {
$current_image = imagecreatefrompng($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagepng($canvas, $filename, 100);
}
さらにコードはありますか?あなたはその声明の後に$ canvasで何をしていますか? – mikevoermans
その画像の中には何がありますか?たぶん33シンボルのエラーメッセージですか? –
すべてのコードがあります。キャンバスはif文のすぐ上に定義されています。そして、ええ、私はエラーの33シンボルがあると信じています。どんな写真もPNGだと思っているので、JPGかもしれないのに、最初と2番目のテストに失敗してしまうということです。 – Ramin