simonsays Posted August 28, 2007 Share Posted August 28, 2007 hi there! My problem is the following. I am trying to write a function that will cut out a fixed-size piece from the CENTER of an uploaded picture. However, my function seems to always cut out a piece from the bottom right corner of the image (filling the difference with black), although the image itself is rather large and the coordinates are given. Thanks in advance! Here's the code! function CreateThumb($filename) { $source = imagecreatefromjpeg($filename); $width = imagesx($source); $height = imagesy($source); $output_width = 215; $output_height = 212; $center_hor = $width/2; $center_vert = $height/2; $src_x = $center_hor - $output_width/2; $src_y = $center_vert + $output_height/2; $output = imagecreatetruecolor($output_width, $output_height); imagecopyresampled($output, $source, 0, 0, $src_x, $src_y, $output_width, $output_height, $width, $height); $new = basename($filename); imagejpeg($output, dirname($filename).'/tn'.$new, 100); imagedestroy($source); imagedestroy($output); } } Quote Link to comment https://forums.phpfreaks.com/topic/67135-cut-out-picture/ Share on other sites More sharing options...
Barand Posted August 28, 2007 Share Posted August 28, 2007 try $src_y = $center_vert - $output_height/2; // change + to - Quote Link to comment https://forums.phpfreaks.com/topic/67135-cut-out-picture/#findComment-336704 Share on other sites More sharing options...
simonsays Posted August 29, 2007 Author Share Posted August 29, 2007 thanks, it's better now? but why doesn't the picture stretch to the limits? it's filled with black: http://www.kashmirecarpet.com/pics/tn9FD5~1.JPG Quote Link to comment https://forums.phpfreaks.com/topic/67135-cut-out-picture/#findComment-337144 Share on other sites More sharing options...
Barand Posted August 29, 2007 Share Posted August 29, 2007 try imagecopyresampled($output, $source, 0, 0, $src_x, $src_y, $output_width, $output_height, $output_width, $output_height); Quote Link to comment https://forums.phpfreaks.com/topic/67135-cut-out-picture/#findComment-337155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.