-3

Would anybody know how to edit the following code to display the vertical images in the directory accurately? The default seems to be horizontal. Thanks very much.

<?php
$files = glob("images/*.*");
for ($i=0; $i<count($files); $i++)
{
$num = $files[$i];
echo '<img src="'.$num.'" alt="">'."<br>
<br>
<br>
";
}
?>
  • are you taking about page layout or image orientation? –  Jan 24 '13 at 22:54
  • Probably `` or so. – mario Jan 24 '13 at 23:04
  • Thanks for reading. Image orientation, I think. The images in the folder have the correct orientation built in. If I download one and view it on my computer it shows correctly but when the script reads it live online they all get stacked horizontally. – David Neumayer Jan 24 '13 at 23:10
  • your code says show one after another with 3 line breaks between each - this is not happening? –  Jan 24 '13 at 23:20
  • Yes, but they are all displayed landscape even though some of them are portrait. I think I'm supposed to use getimagesize to check portrait or landscape. – David Neumayer Jan 24 '13 at 23:24
  • Possible duplicate of http://stackoverflow.com/questions/12026441/is-there-a-way-to-tell-browsers-to-honor-the-jpeg-exif-orientation – Fabian Schmengler Jan 25 '13 at 00:23
  • can't believe how many comments it took to finally understand what you wanted. –  Jan 25 '13 at 01:26

1 Answers1

0

Even I didn't understand what you mean saying "vertical images", getting only images from a directory is more simple in your case;

$images = glob('/path_of_images/*.{jpeg,jpg,png,gif}', GLOB_BRACE);
foreach ($images as $image) {
    // so you can check the current image is image that you are looking for
    $image_data = exif_read_data($image);
    if ($image_data that im looking for)
        printf('<img src="path_of_images/%s" alt=""><br>', basename($image));
    // or check size
    $image_size = getimagesize($image);
    if ($image_size[0] > $image_size[1]) {
        // this is landscape???

See more details here: http://php.net/manual/en/function.exif-read-data.php

Kerem
  • 11,377
  • 5
  • 59
  • 58
  • Hi qeremy. Thanks for your help. The script I have works as is. What I mean is there are some portrait and some landscape images in the images directory on the server. I'm not that technical but somehow each jpg has information stored in it that makes your computer application know (i.e. Photoshop) if the image is meant to be viewed landscape or portrait. The script I have doesn't have that ability so all images are displayed landscape which means the portrait pictures are horizontal not vertical on the php generated layout on the webpage. – David Neumayer Jan 24 '13 at 23:45
  • So you want only images that "not generated via PHP"? I think it should be better to say "what you want to do with PHP". – Kerem Jan 24 '13 at 23:49
  • Well, I'm looking for a PHP code that will read the jpg Exif tag to determine the proper orientation, landscape or portrait. – David Neumayer Jan 24 '13 at 23:58
  • OK see update. By the way, how PHP understands that image is "landscape or portrait", maybe its dimensions can help, but I don't know. – Kerem Jan 25 '13 at 00:20
  • Great, thanks. I'm not good at php but I'll try to get it to work. – David Neumayer Jan 25 '13 at 00:38