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 Link to comment https://forums.phpfreaks.com/topic/59288-solved-aspect-ratio/ 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 Link to comment https://forums.phpfreaks.com/topic/59288-solved-aspect-ratio/#findComment-294496 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. Link to comment https://forums.phpfreaks.com/topic/59288-solved-aspect-ratio/#findComment-294499 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... Link to comment https://forums.phpfreaks.com/topic/59288-solved-aspect-ratio/#findComment-294553 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."\" />"; ?> Link to comment https://forums.phpfreaks.com/topic/59288-solved-aspect-ratio/#findComment-294562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.