Jump to content

GD Library - Cropping


Splash

Recommended Posts

Hi all  ;D

 

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 has hoping someone could help me edit 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($modwidth, $modheight) ; 
$image = imagecreatefromjpeg($file) ; 
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 

imagejpeg($tn, $save, 100); 

?>

 

Thanks a lot  ;D

Link to comment
https://forums.phpfreaks.com/topic/61856-gd-library-cropping/
Share on other sites

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.