Hi
I am using this code to read all images from a specific folder but now I want to correctly orientate them.
I am not sure how to go about implementing exif. ANy suggestions would be appreciated.
<?php
$files = glob("images/Gallery/February/Uploaded/*.*");
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
echo '<img src="'.$image .'" alt="Random image" style="border:2px solid #666; width:100%; margin: 5px;" />'."<br /><br />";
}
?>
Thanks
Using exif with glob
Moderator: General Moderators
Re: Using exif with glob
Take a look at the comments for exif_read_data. A few of them show how to detect image orientation.
If you want to adjust the image so it's correctly oriented, you'll need to actually modify the image. That can be with GD or ImageMagick. You'd only do this once - not every time this page is loaded. It looks like you're dealing with uploaded files so really you should be doing it during the upload process.
If you just want to adjust the image as it displays on the page, leaving the image in whatever orientation, then you can use CSS transforms to rotate the <img>. But fixing the image would be better.
If you want to adjust the image so it's correctly oriented, you'll need to actually modify the image. That can be with GD or ImageMagick. You'd only do this once - not every time this page is loaded. It looks like you're dealing with uploaded files so really you should be doing it during the upload process.
If you just want to adjust the image as it displays on the page, leaving the image in whatever orientation, then you can use CSS transforms to rotate the <img>. But fixing the image would be better.
Re: Using exif with glob
Thanks requinix for your reply.As you can probably tell I am very new to php.
The problem is I have set up a general 'dump' folder where pictures from my phone are automatically placed when i take a picture on my phone. This was quickly done as to create a kind of adhoc phone gallery page at a wedding. So the pages are not uploaded as such but just dumped into a folder via sftp. This folder is then read by the above code. Its not ideal but I guess i need to rotate the images as they are read in and not when they are uploaded. Is this possible? Thanks again.
The problem is I have set up a general 'dump' folder where pictures from my phone are automatically placed when i take a picture on my phone. This was quickly done as to create a kind of adhoc phone gallery page at a wedding. So the pages are not uploaded as such but just dumped into a folder via sftp. This folder is then read by the above code. Its not ideal but I guess i need to rotate the images as they are read in and not when they are uploaded. Is this possible? Thanks again.