dstobkpm908182 2014-08-12 16:44
浏览 102
已采纳

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

I have a script that works fine on most images but it is flipping this image upside down:

This Image Will Flip For Some Odd Reason

Here is the script I'm using:

    <?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条回答 默认 最新

  • dtcpvz8162 2014-08-12 16:55
    关注

    It's because the image is actually upside down. Some of the viewers you are using are looking at the exif data and flipping it for you. Check here... http://imgops.com/https://www.apple.com/v/iphone-5s/gallery/b/images/download/photo_4.jpg#photo-gallery4

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。