changeSize(); Just something I quickly made
Posted: Fri May 06, 2011 11:22 pm
I just quickly made this code, it resizes images. You just put the image url, max height and max width. It takes a little while to do it though and I don't know if there is any errors yet, only just made it and tested it and seems fine. It keeps it in the same aspect ratio, just resizes it. If there is errors, tell me else it's going into my libary, core thing.
Version 1
Version 1
function changeSize($image, $height, $width) { @$type = end(explode(".", $image)); if ($type=="jpg"||$type=="jpeg"||$type=="png"||$type=="gif"||$type=="bmp") { if ($height>$width) $max = $width; else $max = $height; list($iheight, $iwidth) = getimagesize($image); if ($iheight>$iwidth) $h = $iheight; else $h = $iwidth; $p = $h/$max; if ($h==$iheight) { $nheight = $max; $nwidth = round(($iheight/$iwidth)*$max); } else { $nwidth = $max; $nheight = round(($iwidth/$iheight)*$max); } echo "<img src='$image' width='$nwidth' height='$nheight' />"; } else{ echo "The image is not supported!"; } }Version 2
function changeSize($image, $height, $width) { $type = substr($image, strrpos($image, ".") +1); if ($type=="jpg"||$type=="jpeg"||$type=="png"||$type=="gif"||$type=="bmp") { if ($height>$width) $max = $width; else $max = $height; list($iwidth, $iheight) = getimagesize($image); if ($iheight<=500 && $iwidth<=500) { if ($iheight>$iwidth) $h = $iheight; else $h = $iwidth; $p = $max/$h; $nheight = round($iheight*$p); $nwidth = round($iwidth*$p); echo "<img src='$image' width='$nwidth' height='$nheight' />"; } else echo "File too big."; } }