/**
* Processing JPEG images with orientation picture rollover information
* param $imagePath Picture Resource path
* param $dscPath Target path
* The exif Orientation parameter in the photo allows you to see photos in the right direction without manual rotation (provided that the image browser supports, Windows does not support)
*
* */
public static function Delimgorientation ($imagePath, $dscPath = null)
{
/* Exif_imagetype ($imagePath) return 2 for JPGE, photo taken for possible digital camera
, may contain orientation information, first determine the picture resource exists and is jpeg*/
if (!file_exists ($imagePath) | | exif_imagetype ($imagePath)! = 2) {
return false;
}
$exifInfo [' Orientation '] value 1 is not rotated 3 is rotated 180 degrees 6 is clockwise 90 degrees 8 is counterclockwise 90 degrees
$exifInfo = @read_exif_data ($imagePath, ' Exif ', 0);//Get EXIF information for pictures
if ($exifInfo && in_array ($exifInfo [' Orientation '], Array (3, 6, 8))) {//If the picture Orientation flipped, copy the image
$size = getimagesize ($imagePath);
$weight = $size [0];
$height = $size [1];
$DSTIMG = @imagecreatetruecolor ($weight, $height);//Create Target image
$SRCIMG = @imagecreatefromjpeg ($imagePath);//Read source image
Imagecopy ($DSTIMG, $srcImg, 0, 0, 0, 0, $weight, $height);//Copy Image
$dscPath = Isset ($dscPath)? $dscPath: $imagePath,//If the destination picture path is not set to overwrite the original picture
Imagejpeg ($DSTIMG, $dscPath);//output picture (overwrite the original picture)
Imagedestroy ($DSTIMG);//Release image memory
Imagedestroy ($SRCIMG);
}
}
Reprint please indicate the source
Some browsers intelligently flip pictures, PHP to judge and copy (overwrite) JPEG images with orientation picture rollover information