image icon indicating copy to clipboard operation
image copied to clipboard

Feature Request: Image Auto Crop

Open petsoukos opened this issue 3 years ago • 3 comments

Hello,

It would be nice to have the option to auto crop images with imagecropauto (GD) / trimImage (imagick)

petsoukos avatar Jul 07 '21 08:07 petsoukos

@petsoukos, It's pretty easy to do this as long as the option is not available.

In GD:

$img = ImageManagerStatic::make(PATH_TO_ORINGIN_IMAGE);

$croppedImg = imagecropauto($img->getCore(), IMG_CROP_SIDES);
$croppedImg = ImageManagerStatic::make($cropedImg);

Then use $croppedImg as pleased.

I suppose with imagick is similar

jdgrieco avatar Jul 10 '22 13:07 jdgrieco

@petsoukos, It's pretty easy to do this as long as the option is not available.

In GD:

$img = ImageManagerStatic::make(PATH_TO_ORINGIN_IMAGE);

$croppedImg = imagecropauto($img->getCore(), IMG_CROP_SIDES);
$croppedImg = ImageManagerStatic::make($cropedImg);

Then use $croppedImg as pleased.

I suppose with imagick is similar

Even better, with less resources:

$img = ImageManagerStatic::make(PATH_TO_ORINGIN_IMAGE);
$img->setCore(imagecropauto($img->getCore(), IMG_CROP_SIDES));

jdgrieco avatar Jul 10 '22 13:07 jdgrieco

@jdgrieco Thank you for taking the time to reply! I did not have time to investigate a solution even since way back when I posted the feature request. I think I can implement it, maybe even do a PR.

petsoukos avatar Jul 25 '22 07:07 petsoukos

Use the trim() method for "auto cropping" solid color background sections.

petsoukos avatar Oct 13 '22 13:10 petsoukos