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

藏色散人
Release: 2023-04-07 06:22:01
forward
3435 people have browsed it

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;
    }
}
Copy after login

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!

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template