How on php , you can get the orientation of the image (for example: the orientation of the image is horizontal, vertical, square)?
|
2 answers
Well, for this you first need to get the width and height of the image using the function getimagesize () , and then compare the width and height.
$foto = "hummer.jpg"; echo '<img src = "'.$foto.'" />'; echo "<br>"; // ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΌΠ°ΡΡΠΈΠ², ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠΈΠΉ ΡΠ°Π·ΠΌΠ΅ΡΡ ΠΈ ΡΠΈΠΏ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ $size = getimagesize ("$foto"); $flag = array( 1=>'GIF', 2=>'JPG', 3=>'PNG', 4=>'SWF', 5=>'PSD', 6=>'BMP', 7=>'TIFF(Π±Π°ΠΉΡΠΎΠ²ΡΠΉ ΠΏΠΎΡΡΠ΄ΠΎΠΊ intel)', 8=>'TIFF(Π±Π°ΠΉΡΠΎΠ²ΡΠΉ ΠΏΠΎΡΡΠ΄ΠΎΠΊ motorola)', 9=>'JPC', 10=>'JP2', 11=>'JPX' ); /// == ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π²ΡΡΠΎΡΡ ΠΈ ΡΠΈΡΠΈΠ½Ρ ΡΠΎΡΠΎ == /// $height_img = $size[0]; // ΠΡΡΠΎΡΠ° ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ $width_img = $size[1]; // Π¨ΠΈΡΠΈΠ½Π° ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ if ($height_img == $width_img) {echo "ΠΠ²Π°Π΄ΡΠ°ΡΠ½Π°Ρ";} elseif ($height_img > $width_img) {echo "ΠΠΎΡΠΈΠ·ΠΎΠ½ΡΠ°Π»ΡΠ½Π°Ρ";} else {echo "ΠΠ΅ΡΡΠΈΠΊΠ°Π»ΡΠ½Π°Ρ";}; /// == ΠΠ»Ρ ΠΏΡΠΈΠΌΠ΅ΡΠ° ΡΡΠΎ Π²ΡΠ²ΠΎΠ΄ΠΈΡ ΡΡΠ½ΠΊΡΠΈΡ getimagesize() == /// echo "<br><br>"; echo "Π¨ΠΈΡΠΈΠ½Π°: " . $size[0] .'<br>'; echo "ΠΡΡΠΎΡΠ°: " . $size[1] .'<br>'; echo "Π’ΠΈΠΏ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ: " . $flag[$size[2]] .'<br>'; echo "Π¨ΠΈΡΠΈΠ½Π° ΠΈ ΠΡΡΠΎΡΠ°: " . $size[3] .'<br>'; |
The orientation and dimension of the sides are not always related, if that ... If there is EXIF ββdata in the picture, you can try to determine from them:
$file = 'path_to/image.jpg'; $exif = exif_read_data($file); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: $image = imagerotate($image, 180, 0); break; case 6: $image = imagerotate($image, -90, 0); break; case 8: $image = imagerotate($image, 90, 0); break; } } |
