shage Posted July 10, 2007 Share Posted July 10, 2007 In url it has &h=??? the height will be set by user, but should have a max of say 300, the pic will be 300 by whatever so that if they pick to big it will just use the standard pic size, how would i go about keeping the aspect ratio, ive looked but no luck Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 10, 2007 Share Posted July 10, 2007 Use algebra to solve for the new width. o = original, n = new, w = width, h = height ow/oh = nw/nh, (nh*ow)/oh = nw Quote Link to comment Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 There is an example of resizing by percentage in the man page for imagecopyresized, should be pretty easy to do from there. Quote Link to comment Share on other sites More sharing options...
Carterhost Posted July 10, 2007 Share Posted July 10, 2007 It's not foolproof, but if you just specify the height in the image tag (i.e. no width) then the aspect ratio is usually kept... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 10, 2007 Share Posted July 10, 2007 this is what i use to resample on the fly with out GD its pretty good (getImageSize is it) <?php $image = "myimage,/pg"; $tempimg = getImageSize($image); $size = $tempimg[3]; $size = explode("\"",$size); $width = $size[1]; $height = $size[3]; while($height > $maxheight || $width > $maxwidth) { $width = .99*$width; $height = .99*$height; } echo "<img src=\"myimage.jpg\" width=\"".$width."\" height=\"."$height."\" />"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.