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
Share on other sites

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.