g3mma111 Posted June 10, 2007 Share Posted June 10, 2007 I am new to PHP and need help with a resizing script. I realise that there are lots of other posts like this but i have been through them and cant apply them to my case. I have an image rating website and on the homepage it selects a picture at random to display. Problem is that the pic is often too wide and messes up the page. I need to make it so that the image is resized in proportion if the width is over 500. Here is the bit i code that i think it goes into: <td height="19" td width="400"colspan="4" align="center" ><? print $pic ?> </td> Any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/54988-help/ Share on other sites More sharing options...
Caesar Posted June 10, 2007 Share Posted June 10, 2007 Why don't you resize all thumbs to be uniform in width? Or even simpler...just define a % in the image width within the image tag. ;-) Quote Link to comment https://forums.phpfreaks.com/topic/54988-help/#findComment-271866 Share on other sites More sharing options...
Hypnos Posted June 10, 2007 Share Posted June 10, 2007 There are several ways to do this. 1. Make a "gateway" image script in PHP. Reference it like you would an image (IE: <img src="gateway.php">. Use GD functions to randomly grab an image, and resize it on the fly. CPU usage on your server will be a bit high, because it's doing an image resize on every page load. Of course, there are cacheing methods/functions. 2. If all of your pictures are the same aspect ratio (IE: 4:3), then you can force the user's browser to downsize them. <img src="<?php echo $pic; ?>" width="400" height="300"> If they aren't all the same aspect ratio, just use GD functions to get the image size, and calc it from there. http://us2.php.net/gd 3. The easiest way is just to make thumbnails of all your images. There are tons of programs out there that will do batches of thumbnails. You can even write a PHP script to do it. Quote Link to comment https://forums.phpfreaks.com/topic/54988-help/#findComment-271870 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.