Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/54988-help/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/54988-help/#findComment-271870
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.