How to detect shot angle of photo, and auto rotate for website display like desktop apps do on viewing?

前端 未结 4 1326
我在风中等你
我在风中等你 2020-11-29 00:30

If I take a photo with a camera it stores the orientation/angle of the apparatus so when I view the image on the PC with a good app, it shows auto-rotated to 0.

But

4条回答
  •  一向
    一向 (楼主)
    2020-11-29 00:54

    The rotation flag is stored as part of the EXIF data (see this article for more info).

    You will need to read the rotation flag from the EXIF data in PHP and then rotate the image to suit. There are a variety of PHP EXIF libraries, if you have the web server set up with the extension installed you would be able to use the PHP provided library.

    I would suggest rotating the image once on upload (e.g. using the GD library - most PHP installations these days seem to come with it), so that you don't need to worry about clearing the EXIF rotation data (not sure how easy this is with PHP, I've never tried it).

提交回复
热议问题