PHP图像调整大小和裁剪有时会将图像上下翻转

PHP图像调整大小和裁剪有时会将图像上下翻转,php,gd,Php,Gd,我有一个脚本,可以在大多数图像上正常工作,但它将此图像翻转过来: 以下是我正在使用的脚本: <?php $image = imagecreatefromjpeg('photo_4.jpg'); $filename = 'TEMP.jpg'; $thumb_width = 100; $thumb_height = 100; $width = imagesx($image); $height = imagesy($image); $original_aspect = $widt

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

以下是我正在使用的脚本:

    <?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);

这是因为图像实际上是颠倒的。您正在使用的一些查看器正在查看exif数据并为您翻转它。检查这里

非常感谢,伙计,这意味着我的代码很好;)。谢谢你的帮助