Is there a way to tell browsers to honor the jpeg exif orientation?

前端 未结 7 1449
轻奢々
轻奢々 2020-11-30 02:12

I know that the automatic rotation of JPG files is disabled in browsers.

They can not enable it because it would break the layout of some websites.

Is there

相关标签:
7条回答
  • 2020-11-30 03:06

    I've written a little php script which rotates the image. Be sure to store the image in favour of just recalculate it each request.

    <?php
    
    header("Content-type: image/jpeg");
    $img = 'IMG URL';
    
    $exif = @exif_read_data($img,0,true);
    $orientation = @$exif['IFD0']['Orientation'];
    if($orientation == 7 || $orientation == 8) {
        $degrees = 90;
    } elseif($orientation == 5 || $orientation == 6) {
        $degrees = 270;
    } elseif($orientation == 3 || $orientation == 4) {
        $degrees = 180;
    } else {
        $degrees = 0;
    }
    $rotate = imagerotate(imagecreatefromjpeg($img), $degrees, 0);
    imagejpeg($rotate);
    imagedestroy($rotate);
    
    ?>
    

    Cheers

    0 讨论(0)
提交回复
热议问题