Retrieve image orientation in PHP

后端 未结 6 990
闹比i
闹比i 2021-02-04 06:54

How can I get the image orientation (landscape or portrait) of an image (JPEG or PNG) in PHP?

I created a php site where users can upload pictures. Before I scale them

6条回答
  •  灰色年华
    2021-02-04 07:30

    I use a generalized scaling down algorithm like . ..

       function calculateSize($width, $height){
    
                if($width <= maxSize && $height <= maxSize){
                    $ratio = 1;
                } else if ($width > maxSize){
                    $ratio = maxSize/$width;
                    } else{
                        $ratio = maxSize/$height;
                        }
    
            $thumbwidth =  ($width * $ratio);
            $thumbheight = ($height * $ratio);
            }
    

    Here max size is the one I initialized to something like 120px for both height and width . . . so that the thumbnail does not exceed that size . . ..

    This Works for me which is irrespective of landscape or portrait orientation and can be applied generally

提交回复
热议问题