Some browsers intelligently flip pictures, PHP to judge and copy (overwrite) JPEG images with orientation picture rollover information

Source: Internet
Author: User

/**
* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.