raryre23 Posted May 27, 2007 Share Posted May 27, 2007 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!! Link to comment https://forums.phpfreaks.com/topic/53138-help-needed-on-image-resize-simple-question/ Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 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 Link to comment https://forums.phpfreaks.com/topic/53138-help-needed-on-image-resize-simple-question/#findComment-262532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.