deakjahn / crop_image

An image cropper widget. Supports mobile, web and desktop.
https://pub.dev/packages/crop_image
MIT License
56 stars 31 forks source link

Additional "eraser" feature #52

Closed monsieurtanuki closed 4 months ago

monsieurtanuki commented 4 months ago

In our project we now use the crop tool for receipts. In some cases receipts contain user data inside the cropped area, and we should not display/upload it. With an eraser button, the user would be able to erase part of the image. While still cropping it.

deakjahn commented 4 months ago

Sorry but this package does no image manipulation at all. It just gives the rectangle, as you know. A long shot but maybe a plugin approach that can manipulate the image separately but I really don't know if it's warranted...

monsieurtanuki commented 4 months ago

@deakjahn What would be the solution then? I can imagine

What about adding an optional additionalDrawing parameter in getCroppedBitmap, something like void Function(Canvas)?:

additionalDrawing: (Canvas canvas) {
  final Paint myPaint = Paint()
    ..strokeWidth = SmoothBarcodeScannerVisor.STROKE_WIDTH
    ..color = Colors.white
    ..style = PaintingStyle.stroke;
  canvas.drawPath(myPath, myPaint);
}
monsieurtanuki commented 4 months ago

As you see, the impact would be limited on crop_image, and that would look like this: Screenshot_1717091892

monsieurtanuki commented 4 months ago

Working on the subject. cf. https://github.com/openfoodfacts/smooth-app/issues/5301 It looks like the only change would be an additional optional CustomPainter in getCroppedBitmap.

deakjahn commented 4 months ago

I can't yet see how that would be used. I mean, croppedBitmap() is purely a convenience function that's in the package mostly to avoid people always asking the first question of 'but what do I do with the crop rectangle when done'? The package itself doesn't use it and you're never forced to use the function from the package, you can process your crop rectangle any way you see fit. So why would it be advantageous to integrate it into the cropper?

monsieurtanuki commented 4 months ago

The fact that I need this feature in a concrete use-case shows that i's not just a theoretical "what if / just in case" feature request.

You're right if you're talking about a fixed crop widget: a Widget with an input file, a crop grid and a "save cropped image" button. No need to change that.

But it's already a bit different now, with the controller and separate "rotate" widgets: developers can use their own buttons and their own icons, put them where they want, or even not display any "rotate" buttons at all.

If we're rather talking about a crop toolkit we keep the CropImage as a turnkey solution, but provide flexibility.

deakjahn commented 4 months ago

If you think that it's only an added callback, sure, go ahead, try it.

monsieurtanuki commented 4 months ago

Thank you @deakjahn! I haven't finished my code and tests yet, but on the crop_image side that will be just a CustomPainter? parameter here and there. I keep you posted.

deakjahn commented 4 months ago

Implemented by https://github.com/deakjahn/crop_image/pull/53.