troubleshooting Question

GD Library- Crop and Resize

Avatar of Mr_Splash
Mr_Splash asked on
PHP
4 Comments1 Solution2299 ViewsLast Modified:
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($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100);

?>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros