Jump to content

Help needed on image resize - simple question..!


raryre23

Recommended Posts

im very unexperienced with PHP and was wondering if someone could help me with this script:

 

                    <td height="19" align="center"> </td>

                    <td height="19" colspan="4" align="center" ><? print $pic;?></td>

                  </tr>

 

i need to make it so that the picture that is printed is resized if the width is over 400 wide and then the height to be resized in proportion.

 

i realise that there are probably millions of other topics linked to this but i am so clueless when it comes to php that i am unable to apply their answers to my case.

 

any help would be appreciated!!

Create a new php script (called image.php) and paste this into it

 

<?php
// File and new size
$filename = $_GET['img']; //may want to change this to default image path ie "images\".$_GET['img']
$newWidth = $_GET['width'];

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$percent = $newWidth / $width;
//$newWidth = $newWidth;
$newHeight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newWidth , $newHeight );
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?> 

 

 

now use this for calling the image

<?php
echo "<img src='image.php?img=test.jpg&width=400' />";
?>

 

please note this is untested

 

EDIT:

and its setup for jpgs only

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.