PHP图像调整大小和裁剪有时翻转图像颠倒

时间:2014-08-12 16:44:48

标签: php gd

我有一个可以在大多数图像上正常工作的脚本,但它正在翻转这个图像:

This Image Will Flip For Some Odd Reason

这是我正在使用的脚本:

    <?php
$image = imagecreatefromjpeg('photo_4.jpg');
$filename = 'TEMP.jpg';

$thumb_width = 100;
$thumb_height = 100;

$width = imagesx($image);
$height = imagesy($image);

$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;

if ( $original_aspect >= $thumb_aspect )
{
// If image is wider than thumbnail (in aspect ratio sense)
$new_height = $thumb_height;
$new_width = $width / ($height / $thumb_height);
}
else
{
// If the thumbnail is wider than the image
$new_width = $thumb_width;
$new_height = $height / ($width / $thumb_width);
}

$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );

// Resize and crop
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
0 - ($new_height - $thumb_height) / 2, // Center the image vertically
0, 0,
$new_width, $new_height,
$width, $height);
imagejpeg($thumb, $filename, 80);

1 个答案:

答案 0 :(得分:1)

这是因为图像实际上是颠倒的。您正在使用的一些观看者正在查看exif数据并为您翻转它们。点击此处... http://imgops.com/https://www.apple.com/v/iphone-5s/gallery/b/images/download/photo_4.jpg#photo-gallery4