brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.14k stars 255 forks source link

Best way to trim white space around pictures? #627

Open yoanhg421 opened 3 months ago

yoanhg421 commented 3 months ago

I’m trying to do a trim on an image with less than ideal quality and some JPEG artifacts. The trim function works well and is very fast but it’s looking for perfect white color and sometimes this causes some images to have extra space around them.

I tried increasing the contracts to remove the artifacts then findTrim and then copyCrop but this is very slow when processing a list of pictures

I also tried chaining the methods but the findTrim breaks the CMD sequence so I can’t do that.

I also noticed that each method that returns a new image ends up altering the original decoded variable. This causes me having to decode the image into two separate variables. One for the find trim and the other to actually crop the image. This looks like a Dart problem but I’m not sure.

Any advice on this would be great.

brendan-duncan commented 3 months ago

It's true, the trim functions don't have much wiggle room for things like jpeg artifacts. . I'm not really sure what to do about it. Not even Photoshop's trim deals with that. Maybe a tolerance parameter, look at the luminance of the pixel and trim it if the luminance is within the tolerance, but I'm not sure what that would actually do.

And it seems like I neglected to make a command for findTrim, which you could feed into copyCrop. I'll have to think on that some more, see if I can figure something out for that.