jeudi 29 août 2019

Function return error: Incorrect APP1 Exif Identifier Code

I am beginner in Laravel and Php. In my project I use Laravel 5.8 and PHP 7.2. I have this code:

function correctImageOrientation($filename)
{
    if (function_exists('exif_read_data')) {
        $exif = exif_read_data($filename);
        if ($exif && isset($exif['Orientation'])) {
            $orientation = $exif['Orientation'];
            if ($orientation != 1) {
                $img = imagecreatefromjpeg($filename);
                $deg = 0;
                switch ($orientation) {
                    case 3:
                        $deg = 180;
                        break;
                    case 6:
                        $deg = 270;
                        break;
                    case 8:
                        $deg = 90;
                        break;
                }
                if ($deg) {
                    $img = imagerotate($img, $deg, 0);
                }
                imagejpeg($img, $filename, 95);
            }
        }
    }
}

and sometimes I have this error:

[2019-08-30 08:23:29] public.ERROR: exif_read_data(87db75b052e7a9f1edfbbe9b5d9defca.jpg): Incorrect APP1 Exif Identifier Code {"userId":3,"exception":"[object] (ErrorException(code: 0): exif_read_data(87db75b052e7a9f1edfbbe9b5d9defca.jpg): Incorrect APP1 Exif Identifier Code at /usr/home/name/domains/name.com/correctImageOrientation.php:6)

How can I repair it? Maybe its possible add something like "try"?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire