脚本宝典收集整理的这篇文章主要介绍了php – 我服务的图像不正确,它们都显示为旋转90度,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$filename = $_GET["filename"]; if ($filename == null || strlen($filename) < 1){ return null; } $fp = foPEn($filename,'rb'); // send the right headers header("Content-type: image/jpeg"); header("Content-Length: " . filesize($filename)); // dump the picture and stop the script fpassthru($fp); exIT;
当我通过浏览器运行这个@L_126_1@文件时(比如在浏览器的地址栏中调用此脚本),肖像图像显示肖像.
但是当我在HTML文件中运行它时(我动态设置了img元素的src)所有肖像图像都显示为横向(如旋转90度).
我应该在响应(-headers)中包含图像是横向还是纵向的内容?
这是我在html中加载图像的方式:
document.getElementById('next').src = "image.PHP?filename=" + data;
您可以通过ImageMagick –auto-orient http://imagemagick.org/Usage/photos/#orient在服务器上旋转图片
你也可以“飞行”旋转它.只需通过exif_read_data()获取Exif信息,如果在’orientation’中有3(180deg),6(90CW)或8(-90CCW),则旋转它
// dump the picture and stop the script $source = imagecreatefromjpeg($filename); $exif = exif_read_data($filename); if (isset($exif['Orientation'])) { switch($exif['Orientation']) { case 3: // 180 degree $rotate=imagerotate($source,180,0); break; case 6: // 90 CW $rotate=imagerotate($source,-90,0); break; case 8: // 90 CCW $rotate=imagerotate($source,90,0); break; default: $rotate=imagerotate($source,0); break; } imagejpeg($rotate); imagedestroy($source); imagedestroy($rotate); } else { imagejpeg($source); imagedestroy($source); }
但当然最好准备一次所有图片.
以上是脚本宝典为你收集整理的php – 我服务的图像不正确,它们都显示为旋转90度全部内容,希望文章能够帮你解决php – 我服务的图像不正确,它们都显示为旋转90度所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。