santocki
asked on
Setting the max-width and max-height for images using PHP
I have developed a forum. User are able to insert HTML tags directly. So user can paste a code like:
<img src="http://www.website.com/big_image.jpg" />
sometimes it has the width and height attribute
<img src="http://www.website.com/big_image.jpg" width="1000" />
But I want to limit the max image size automatically, so it will not stretch out the fixed forum length if the image is larger, is that possible?
What I want to do is:
1. if the "width" is already set but it's greater than the max permitted like 500px, then change it to 500px
2. If it does not have the width, then just add the width
3. It should not slow down the speed by loading the remote image file remotely using php functions to find out the width
Thank you.
<img src="http://www.website.com/big_image.jpg" />
sometimes it has the width and height attribute
<img src="http://www.website.com/big_image.jpg" width="1000" />
But I want to limit the max image size automatically, so it will not stretch out the fixed forum length if the image is larger, is that possible?
What I want to do is:
1. if the "width" is already set but it's greater than the max permitted like 500px, then change it to 500px
2. If it does not have the width, then just add the width
3. It should not slow down the speed by loading the remote image file remotely using php functions to find out the width
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Even when the html code does NOT specify the img width and height explicitly EX:
<img src="test.gif">
the browse will detec/computt the img size automatically and set its size. So, technically speaking, this statement:
"If it does not have the width, then just add the width"
will always be false because the browser will assign a value to it if you did not supply one.
The script below adjusts the size dynamically on the browser, so point #3 is met with no problem.
Open in new window