Mr_Splash
asked on
GD Library- Crop and Resize
Hello
I'm trying to set up a script that will generate thumbnails for an image gallery using GD Library.
I'm using the following script, which resizes the image to 100px x 100px. It's working fine however I was hoping someone could help me customize it so that it shrinks the image by 50% then crops the thumbnail from the center.
<?php
//Input file
$file = 'image.jpg';
//Output file
$save = 'new.jpg';
//Get image dimensions
list($width, $height) = getimagesize($file) ;
//Set new Dimensions
$modwidth = 100;
$modheight = 100;
$tn = imagecreatetruecolor($modw idth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100);
?>
I'm trying to set up a script that will generate thumbnails for an image gallery using GD Library.
I'm using the following script, which resizes the image to 100px x 100px. It's working fine however I was hoping someone could help me customize it so that it shrinks the image by 50% then crops the thumbnail from the center.
<?php
//Input file
$file = 'image.jpg';
//Output file
$save = 'new.jpg';
//Get image dimensions
list($width, $height) = getimagesize($file) ;
//Set new Dimensions
$modwidth = 100;
$modheight = 100;
$tn = imagecreatetruecolor($modw
$image = imagecreatefromjpeg($file)
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100);
?>
ASKER
That's exactly what I need to do, but I'm very new to PHP and I'm afraid I don't know the syntax.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or this should work
<?php
//Input file
$file = 'image.jpg';
//Output file
$save = 'new.jpg';
//Get image dimensions
list($width, $height) = getimagesize($file) ;
//Set new Dimensions
$modwidth = $width/2;
$modheight = ($modwidth/$width)*$height ;
$tn = imagecreatetruecolor(100, 100) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, $modwidth/2, $modheight/2, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100);
?>
<?php
//Input file
$file = 'image.jpg';
//Output file
$save = 'new.jpg';
//Get image dimensions
list($width, $height) = getimagesize($file) ;
//Set new Dimensions
$modwidth = $width/2;
$modheight = ($modwidth/$width)*$height
$tn = imagecreatetruecolor(100, 100) ;
$image = imagecreatefromjpeg($file)
imagecopyresampled($tn, $image, 0, 0, $modwidth/2, $modheight/2, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100);
?>
?