2

i am using php getimagesize to set width and height columns in the database. works fine with with every image except some GIFs shot by an Iphone camera(Live Photos). in that case the width and height are switched. my first thought was to use exif_read_data to check orientation and rotate. But i do not believe this it supports GIFs. what is the best way to identify disoriented images? if this is indeed the issue?

            $img = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $media));
            if (!$img) {
                    echo "!img media: $media";
                return false;
            }
            $tfn = $user_id.''.time().'tmp';
            file_put_contents($tfn, $img);
            $info = getimagesize($tfn);
            unlink($tfn);

            if (($info[0] > 0 && $info[1] > 0 && $info['mime'])) {
                    $mfa = explode('/', $info['mime']);
                    if($mfa[0] != 'image'){
                            echo "not an image";
                            return 0;
                    }
                    $media_format = $mfa[1];
                    if($media_type = "gif") {$media_format = "gif";$media_type = "image";}
                    $media_name = md5("kaa".$page_id."".time()."".$user_id).".".$media_format;
                    $file = rand(0,1000000);
                    $path = "/var/www/html/api/media/posts/".$file;
                    $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $media));

                    if(!file_exists($path))
                            mkdir($path, 0777, true);
                    if(!file_put_contents($path.'/'.$media_name, $data)){
                            return 0;
                    }
                    $media_p = $file.'/'.$media_name;
                    $dimens = $info[0].'x'.$info[1];
                    //echo "info[3] = ";echo $info[3];
            }

`

PIRATE FIFI
  • 261
  • 2
  • 10

0 Answers0