One line image resizing code? How does this work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjrusso
Forum Newbie
Posts: 1
Joined: Fri Feb 15, 2008 5:39 pm

One line image resizing code? How does this work?

Post by mjrusso »

Today I set my sights on trying to learn how to resize images in PHP for display. I failed. Miserably. But out of frustration, I tried the following code:

Code: Select all

<img src="<?php echo $pic; ?>" height="50%">
It actually worked. But I can't figure out why it works.

For whatever reason, the height="%" attribute alone resizes the pic proportionally. No matter the original pic size, it either increases or decreases it to a standard size that I can control by the % value. At about 50%, I get a pic in the ballpark of 300px by 300px (depending on the original dimensions of the pic). 15% gives me about an avatar sized pic and so on. It seems to have an even greater effect inside of a table. To get a picture inside of a table to roughly 300px by 300px, I had to increase the % value by quite a bit.

I tested this on 50 different browser/platform combos and it worked just fine on about 90% of them. Only 4 or 5 of them either didn't display the pic at all or didn't resize them. I haven't looked into why yet. I'm too tired right now.

Anyway, does anyone know what I'm actually doing here? It seems too simple compared to all of the code I've seen on how to resize pics. I can't help but to think a major issue will eventually spring up on me.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: One line image resizing code? How does this work?

Post by yacahuma »

I dont think your image is resizing. Is Just what you see. If you want to try it

use a tools like this

http://www.websiteoptimization.com/services/analyze/
there you can see the real size of the page being downloaded , not just what you think it is
Post Reply