简体   繁体   中英

PHPThumb crop left side and right side of image

I'm trying to get an image and crop it then resize it to a thumbnail using PHPThumb . I want to crop the left side, right side, top and bottom in similar percentages. For example, crop 30% from left and 30% from right side; crop 40% from top bottomwards and 40% from bottom upwards How can I go about it. All I see in the manual is passing the SX value which I suppose only crops it mathematically from the bottom left(where x=0). I need to be able to crop from both sides towards the centre of the image. I hope you get what I mean.

I am using PHPThumb and not something custom since it has good JPEG compression when resizing, therefore the images have the clarity of the originals.

IMPORTANT EDIT : I have been notified that such a feature is not available in PHPThumb, anybody know of any such thumbnaik generator with the above cropping functions?

You could use Imagemagick -shave ( http://www.imagemagick.org/script/command-line-options.php#shave )but would need to calculate the pixels from the percentages first.

Untested code:

$size = getimagesize($input);
$horizontal = round( ($size[0]x0.3), 0);
$vertical = round( $size[1]x0.4), 0);
$cmd = "$input -shave {$horizontal}x{$vertical}";  
exec("convert $cmd output.jpg"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM