Qondio
Front
Intel
IntelMart
Shares
My Qondio
Account
hotnoob > Intel > How to Autosize Images with php

qondio.com/6sQn PRINT EMAIL

How to Autosize Images with php

The simple PHP function will show you how to create an auto-sizing imaging system, which is especially handy when users are uploading their own images that may be a 1000 meters wide and high; it prevents people from destroying the layout to your site.
writePicture
Code:
function writePicture($image, $maxwidth, $maxheight)
{
if($image !== "")
{
list($width, $height, $type, $attr) = getimagesize($image);
if($width > $maxwidth)
{
$constant = $maxwidth/$width;
$width = $constant * $width;
$height = $constant * $height;
}
if($height > $height)
{
$constant = $maxheight/$height;
$width = $constant * $width;
$height = $constant * $height;
}
echo"<img src=\"$image\" width=\"$width\" height=\"$height\" border=\"0\">";
}
else
{
if($maxwidth < 1){ $maxwidth = 100; } if($maxheight < 1) { $maxheight = 100;}
echo"<img src=\"images/pages/missingpic.png\" width=\"$maxwidth\" height=\"$maxwidth\" border=\"0\">";
}
}

A Noobs World © 2007-2008

Contributed by hotnoob on April 6, 2008, at 8:35 PM UTC.

Reactions

No reactions yet.

Rate This Intel

Please login or sign up to rate this intel.

Comments

Please login or sign up to add a comment.

Share

Copyright Notice

The copyright for this content entitled "How to Autosize Images with php" has been specified by the contributor as:

All Rights Reserved

This content may not be copied, distributed or adapted by anyone under any circumstances.

Login Here with
Any Email Address
Any Password
No account? Sign up.

Intel Contributor
This intel was contributed by hotnoob

Qondio Archive
May, 2012
123456
78910111213
14151617181920
21222324252627
28293031


2008
January, February, March, April, May, June, July, August, September, October, November, December
2009
January, February, March, April, May, June, July, August, September, October, November, December
2010
January, February, March, April, May, June, July, August, September, October, November, December
2011
January, February, March, April, May, June, July, August, September, October, November, December
2012
January, February, March, April, May

Sign Up
Not a member yet? Qondio is a powerful network for making it online. If you have a website to promote, we can help. Sign up and get in on the action.

About Qondio
Welcome to Qondio! Discover the awesome power this network can deliver by going to our About page. Or you could skip straight to the Sign Up form.

ABOUT
SUCCESS GUIDE
FEATURES
FAQ
ADVERTISE
CONTACT
USAGE POLICY
PRIVACY POLICY


TWITTER
FACEBOOK