简体   繁体   中英

PHP - cropping image

I have got this image :

在此处输入图片说明

And i need to crop the top and bottom, so i will get this :

在此处输入图片说明

I was searching for a while, but did not find a solution, it needs to be done in PHP.

You can use imagecrop() method to crop any image as follows:

$filename = 'test.JPG';
    $image = imagecreatefromjpeg($filename );
    $x_size = getimagesize($filename)[0];
    $y_size = getimagesize($filename)[1];
    $crop_measure = min($x_size, $y_size);
    header('Content-Type: image/jpeg');
    $crop_array = array('x' =>0 , 'y' => 0, 'width' => $crop_measure, 'height'=> $crop_measure);
    $thumb_image = imagecrop($image, $crop_array);

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