Home >Backend Development >PHP Tutorial >PHP detects if the photo is upside down and rearranges the photo

PHP detects if the photo is upside down and rearranges the photo

藏色散人
藏色散人forward
2019-07-16 15:08:303383browse

PHP detects if the photo is upside down and rearranges the photo

When uploading images from Safari, it is possible that the photos obtained by your server are upside down (depending on the position of the photo button). The following code can ensure that all uploaded photos are in the correct position.

$image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
    switch($exif['Orientation']) {
        case 8:
            $image = imagerotate($image,90,0);
            break;
        case 3:
            $image = imagerotate($image,180,0);
            break;
        case 6:
            $image = imagerotate($image,-90,0);
            break;
    }
}

Related recommendations: "PHP Tutorial"

The above is the detailed content of PHP detects if the photo is upside down and rearranges the photo. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete