如何检测照片的拍摄角度,以及如何像查看桌面应用程序一样自动旋转以显示网站?
如果我用相机拍摄照片,它会存储设备的方向/角度,因此当我使用良好的应用程序在PC上查看图像时,它会自动旋转为0。
但是,当我上传到网站时,它会显示原始角度,因此图像看起来不太好。
如何使用PHP进行检测并旋转图像,并从其元信息中清除此角度标志。
回答:
为此,必须从JPEG文件中读取EXIF信息。您可以使用exifPHP扩展名或使用PEL。
基本上,您必须读取Orientation文件中的标志。这是一个使用exifPHP扩展并WideImage用于图像处理的示例。
<?php$exif = exif_read_data($filename);
$ort = $exif['Orientation'];
$image = WideImage::load($filename);
// GD doesn't support EXIF, so all information is removed.
$image->exifOrient($ort)->saveToFile($filename);
class WideImage_Operation_ExifOrient
{
  /**
   * Rotates and mirrors and image properly based on current orientation value
   *
   * @param WideImage_Image $img
   * @param int $orientation
   * @return WideImage_Image
   */
  function execute($img, $orientation)
  {
    switch ($orientation) {
      case 2:
        return $img->mirror();
        break;
      case 3:
        return $img->rotate(180);
        break;
      case 4:
        return $img->rotate(180)->mirror();
        break;
      case 5:
        return $img->rotate(90)->mirror();
        break;
      case 6:
        return $img->rotate(90);
        break;
      case 7:
        return $img->rotate(-90)->mirror();
        break;
      case 8:
        return $img->rotate(-90);
        break;
      default: return $img->copy();
    }
  }
}
以上是 如何检测照片的拍摄角度,以及如何像查看桌面应用程序一样自动旋转以显示网站? 的全部内容, 来源链接: utcz.com/qa/429680.html

