macdunn Posted January 22, 2015 Share Posted January 22, 2015 Hi all, I am not sure if the Social Media forum is the right place for my question about serverside programming, but I will go ahead anyway. I have a large number (thousands) of photos which I want to easily organise, by name, on my website. Programming the pages (day-by-day) is time-consuming. I can use the glob() function in PHP to get a list of all of my JPG files in a specific sub-directory. I would like to also be able to read the dimensions for each individual photo so that I can have my PHP program write the appropriate sizing (height / width) on-the-fly. However, I cannot seem to find a PHP function to read the dimensions. File size, yes; dimensions, no. Is there a PHP function which I have missed, or a Javascript function, or...? Thanks in advance. -Mac- Quote Link to comment Share on other sites More sharing options...
V.T. Eric Layton Posted January 22, 2015 Share Posted January 22, 2015 Mac, I'll be totally honest with you here... PHP and Javascripting are not within my realm of competency, so I can't help you at all. Stand by, though... there may be others around here who can help you with this. Luck! ~Eric Quote Link to comment Share on other sites More sharing options...
ebrke Posted January 23, 2015 Share Posted January 23, 2015 Does this help at all? http://php.net/manual/en/function.getimagesize.php 1 Quote Link to comment Share on other sites More sharing options...
macdunn Posted January 29, 2015 Author Share Posted January 29, 2015 Hi ebrke, Yes, that is it. I have to first ask myself why I did not immediately see that when I was looking at the Filesystem functions. Then, I see that it is not listed in the Filesystem Functions. Thanks! I knew there was a function, just not exactly what it is. All Hail Scot's Newletter Forums Participants!! -Mac- Quote Link to comment Share on other sites More sharing options...
macdunn Posted January 29, 2015 Author Share Posted January 29, 2015 (edited) Hi All, So, here is a followup on my intended use of the glob() function and the [pointed-out-to-me] getimagesize() function in PHP. Put the following code in an index.php (or whatever you want to call it) file in a directory with JPGs -- foreach (glob("*.jpg") as $filename) { $size = getimagesize ("$filename"); if ($size[3] == 'width="1772" height="1181"') : echo "<img src=\"$filename\" height=118></P> "; else : echo "<img src=\"$filename\" height=177></P> "; endif; echo "$filename</P> </P> "; } This now reads the properties of all the JPGs and displays them according to the height found. I size all of the photos I upload as width=1772 / height-1181 or width=1181 / height=1772 according to whether the photo is horizontal or vertical. I have reduced the height by 10% to display the photo as a thumbnail. I will now enhance the code further for myself, displaying the photos in a TABLE with two-across CELLs. Obviously, the width and height sizes can be read and used dynamically when the hpotos are not saved with consistent dimensions. This will now save me a lot of programming time. During the last Fasnacht season (what is know in other languages and regions as Carnival, Karneval, Mardi Gras and such), a six-week period of costumes, parties and parades, I shot more than 4,000 photos. I just did not want to deal with the program code for my own site and went to Facebook as a quick-and-dirty solution. Now, I will not have to. Thanks again to ALL! -Mac- Edited January 29, 2015 by macdunn 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.