Page 1 of 1

Resizing pictures - constraining proportions

Posted: Wed Aug 31, 2005 6:08 pm
by slindstr
Hello,

I was hoping someone could help me find a solution to my problem. I need to display about 71 pictures of all different dimensions on a web page. I plan on using a loop to display them but I need to resize them and constrain the proportions of each picture at the same time. Any ideas?

Thanks
Steve

Posted: Wed Aug 31, 2005 6:11 pm
by William
Use html and add width='' or height='' just 1 of them to resize to the height you want. Most of the time sence you resize one size it will automaticly do the other for you. But if you want to get more advanced you could use PHP to get the sizes and use math to fix it... But HTML is way easier.

Posted: Wed Aug 31, 2005 6:13 pm
by feyd
use a resizing function, such as one posted in the Code Snippets board (here) while looping. One thing though, resizing that many images at one time (each time the script is run) will eat the processor and make the page run like molasses uphill in a Canadian "breeze."

I'd suggest resizing the images before hand and storing the results, or resizing only when necessary (can be a bit more advanced/involved).

Posted: Thu Sep 01, 2005 3:30 am
by onion2k
William wrote:Use html and add width='' or height='' just 1 of them to resize to the height you want. Most of the time sence you resize one size it will automaticly do the other for you. But if you want to get more advanced you could use PHP to get the sizes and use math to fix it... But HTML is way easier.
Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.. :wink:

Seriously, that's the worst way of doing thumbnails ever. Use GD. Search for "php thumbnail" on here to get examples of code.

Posted: Thu Sep 01, 2005 3:51 am
by s.dot
If I could figure out how to do stuff on the new OS I'd post my thumbnail script, revised edition :P perhaps tommorrow...err I mean later today when I wake up

Thanks

Posted: Thu Sep 01, 2005 6:47 am
by slindstr
Thanks for all of your replies - I appreciciate it. I did find this GD tutorial on the web which seems to be pretty alright:

http://www.tutorialized.com/tutorial/Th ... in-PHP/788

I'll give it a try later today

Thanks again
Steve[/url]

Posted: Thu Sep 01, 2005 8:16 am
by s.dot
that code looks pretty good.

Posted: Thu Sep 01, 2005 9:19 am
by JAM
Just adding some more thoughts.
Do please have in mind that resizing on the fly is, as mentioned, memory/cpu consuming. If the page is under alot of stress you should consider using GD as a means to create physical thumbnails instead of dynamic (as shown in the example url above).

If it's possible to do for your solution that is. ;)

Posted: Thu Sep 01, 2005 10:56 am
by slindstr
What would be the best way to create the physical thumbnails? I don't think I fully get it... (sorry I'm still fairly new to PHP)

Thanks
Steve

Posted: Thu Sep 01, 2005 11:06 am
by feyd
you have the realizing function write the image stream to a file instead of the output stream. Have a look at imageJpeg().

Posted: Thu Sep 01, 2005 11:31 am
by slindstr
So would/could it be one file containing all of the image data, or a file for every image that needs to be resized?

Also would I just make a php page that would not be seen by the public that I would run once and have all of the data be put into the file(s), THEN when the public goes to view the pictures it just reads the file(s) containing the data?

Thanks
Steve

Posted: Thu Sep 01, 2005 11:42 am
by feyd
What I do is:
  1. generate seperate files for each thumb
  2. the thumb creator is apart of the script that displays the gallery
  3. the generated thumb is cached in a seperate location (if another thumb does not exist with the main image).
  4. the thumb creator looks at the thumb's time and the original image's. If the original image is newer or doesn't have a thumb, it generates one. Otherwise, it ignores the image.
This will make the initial page view sluggish as all the thumbs are generated, but after that, the page is quite fast.