Jump to content

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

 

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.