vexious Posted December 28, 2007 Share Posted December 28, 2007 I need some help, and i'm really not sure how to go about doing this. I have a script which will output images onto a page, however images uploaded are of all various sizes. I want all images to have the width of 200 but i want the proportions to be retained. How would i go about doing this? Here the bit of code that displays the image: <div style="text-align: center; padding-top: 5px;"> <a href="$appUrl?t=details&id={$row['id']}&author_id={$row['author_id']}"> <img src="$imageBaseUrl{$row['file_name']}" alt="{$row['tags']}" /> </a> Quote Link to comment https://forums.phpfreaks.com/topic/83488-resize-image/ Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 $max_width = 200; if($width > $max_width) { $height = ($max_width / $width) * $height; $width = $max_width; } That will give you the new sizes for images which are too large. Quote Link to comment https://forums.phpfreaks.com/topic/83488-resize-image/#findComment-424767 Share on other sites More sharing options...
vexious Posted December 28, 2007 Author Share Posted December 28, 2007 I also want it to increase the width of images less than 200 was my main problem. (I know it will look stretched but i need it to) Basically I want all images width 200, and height doesn't matter, just proportional from the orginial size.. Not sure if this is possible really example: if the original Image was: Width:80 height:100 The image displayed should be: Width 200; Height:160 Quote Link to comment https://forums.phpfreaks.com/topic/83488-resize-image/#findComment-424803 Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 Well, still (almost) the same $forced_width = 200; if($width != $forced_width) { $height *= $forced_width / $width; // just made it shorter, it's still doing the same $width = $forced_width; } Quote Link to comment https://forums.phpfreaks.com/topic/83488-resize-image/#findComment-424817 Share on other sites More sharing options...
vexious Posted December 28, 2007 Author Share Posted December 28, 2007 thnaks mate, one last question, how would i put that code into: <div style="text-align: center; padding-top: 5px;"> <a href="$appUrl?t=details&id={$row['id']}&author_id={$row['author_id']}"> <img src="$imageBaseUrl{$row['file_name']}" alt="{$row['tags']}" /> </a> Quote Link to comment https://forums.phpfreaks.com/topic/83488-resize-image/#findComment-424828 Share on other sites More sharing options...
Daniel0 Posted December 28, 2007 Share Posted December 28, 2007 You could get the size of the image using getimagesize() and use the height and width HTML attributes on the img tag. You could also generate a new image with the new size dynamically at each request or you could one time generate a new image and store it on the server. It would be best to choose one of the two last options. Quote Link to comment https://forums.phpfreaks.com/topic/83488-resize-image/#findComment-424948 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.