我提供的图像不正确吗,它们都显示为旋转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;

当我通过浏览器运行此php文件时(例如在浏览器的地址栏中调用此脚本),将显示一个纵向图像。但是,当我在HTML文件中运行该(I设置的src一个的img元件动态地)所有肖像图像示景观(像旋转90度)。

我是否应该在响应(标题)中包含图像为横向或纵向的内容?

这是我在html中加载图像的方式:

document.getElementById('next').src = "image.php?filename=" + data;

这是从我的html页面调用的请求以及图像显示正确时的外观:

在此处输入图片说明

这是不正确的版本 在此处输入图片说明

I can see the headers differ, but does that make a difference? (besides I would know how to set the headers when I set the image source)

One thing I also noticed was that in both cases, when I rightclick and save the image, the filename is image.jfi which I think is a weird extension?

ABelikov

Orientation was setted in Exif. Picture wasn't rotated phisicaly. Image-viewer can to work with it but the browser in tag doesn't rotate it.

Your can rotate pictures on server by imagemagick --auto-orient http://imagemagick.org/Usage/photos/#orient

You can also rotate it "on fly". Just get Exif info by exif_read_data() and rotate it if it has 3(180degree), 6(90CW), or 8(-90CCW) in 'Orientation'

// 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,0);
            break;
    }
    imagejpeg($rotate);
    imagedestroy($source);
    imagedestroy($rotate);
} else {
    imagejpeg($source);
    imagedestroy($source);
}

But of course better to prepare all pictures once.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章