A
A
Arthur2019-04-13 20:34:01
PHP
Arthur, 2019-04-13 20:34:01

How to rotate a photo based on data from EXIF ​​correctly and once?

I welcome everyone!
On the same versions of PHP, the imagecreatefromstring and imagejpeg functions work differently.
For example, there is a code:

if (move_uploaded_file($tmp_filename, $fullpath)) {
    $image = imagecreatefromstring(file_get_contents($fullpath));

    # rotate
    $exif = exif_read_data($fullpath);
    $angles= array(8 => 90, 3 => 180, 6 => -90);
    if(!empty($exif['Orientation']) && isset($angles[$exif['Orientation']])) {
        $image = imagerotate($image, $angles[$exif['Orientation']], 0);
    }
    # rotate

    imagejpeg($image, $fullpath);
}

If you run this example and upload an image with data in exif, then on the local server in PHP 7.3 the image will be loaded as is, on the client server (PHP 7.3) it will rotate to the desired angle.
If all the lines between the "#rotate" comments are removed, then on the local image it rotates itself, on the client's server nothing happens.
The question is how to determine that it will rotate itself and not rotate again if it is not necessary? Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question