Giter VIP home page Giter VIP logo

flutter-custom-image-crop's Introduction

custom_image_crop

An Image cropper that is customizable

pub package Build Status Coverage Status MIT license

customcropcircle customcropsquare customcropcircle

CustomImageCrop

CustomImageCrop(
  cropController: controller,
  image: const AssetImage('assets/test.png'),
),

You can provide the image using any Imageprovider.

Parameters

required image

The image that needs to be cropped

cropController

The controller used to adjust the image and crop it.

overlayColor

The color above the image that will be cropped

backgroundColor

The color behind the image. This color will also be used when there are gaps/empty space after the cropping

shape

The shape of the cropping path.

cropPercentage

How big the crop should be in regards to the width and height available to the cropping widget.

drawPath

How the border of the crop should be painted. default DottedCropPathPainter.drawPath and SolidCropPathPainter.drawPath are provided, but you can create/provide any CustomPaint.

pathPaint

Custom painting for the crop area border style.

canRotate

Whether to allow the image to be rotated.

customProgressIndicator

Custom widget for progress indicator.

ratio

Ratio of the cropping area. If shape`` is set to CustomCropShape.Ratio, this property is required. For example, to create a square crop area, use [Ratio(width: 1, height: 1). To create a rectangular crop area with a 16:9 aspect ratio, use [Ratio(width: 16, height: 9)`.

borderRadius

The radius for rounded corners of the cropping area.

forceInsideCropArea

Whether image area must cover clip path.

Controller Methods

addTransition

void addTransition(CropImageData transition)

Add the position, angle and scale to the current state. This can be used to adjust the image with sliders, buttons, etc.

setData

void setData(CropImageData data)

Set the position, angle and scale to the specified values. This can be used to center the image by pressing a button for example.

reset

void reset()

Reset the image to its default state

onCropImage

Future<MemoryImage> onCropImage()

Crops the image in its current state, this will return a MemoryImage that contains the cropped image

Example

See example/lib

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({
    required this.title,
    Key? key,
  }) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late CustomImageCropController controller;

  @override
  void initState() {
    super.initState();
    controller = CustomImageCropController();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        brightness: Brightness.dark,
      ),
      body: Column(
        children: [
          Expanded(
            child: CustomImageCrop(
              cropController: controller,
              image: const AssetImage('assets/test.png'), // Any Imageprovider will work, try with a NetworkImage for example...
            ),
          ),
          Row(
            children: [
              IconButton(icon: const Icon(Icons.refresh), onPressed: controller.reset),
              IconButton(icon: const Icon(Icons.zoom_in), onPressed: () => controller.addTransition(CropImageData(scale: 1.33))),
              IconButton(icon: const Icon(Icons.zoom_out), onPressed: () => controller.addTransition(CropImageData(scale: 0.75))),
              IconButton(icon: const Icon(Icons.rotate_left), onPressed: () => controller.addTransition(CropImageData(angle: -pi / 4))),
              IconButton(icon: const Icon(Icons.rotate_right), onPressed: () => controller.addTransition(CropImageData(angle: pi / 4))),
              IconButton(
                icon: const Icon(Icons.crop),
                onPressed: () async {
                  final image = await controller.onCropImage();
                  if (image != null) {
                    Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => ResultScreen(image: image)));
                  }
                },
              ),
            ],
          ),
          SizedBox(height: MediaQuery.of(context).padding.bottom),
        ],
      ),
    );
  }
}

flutter-custom-image-crop's People

Contributors

ajmalsalim avatar ikbendewilliam avatar nicolaverbeeck avatar sikandernoori avatar thienduynguyen avatar vanlooverenkoen avatar yumengnevix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter-custom-image-crop's Issues

web on moble issue

hello dear
web version on desktop is ok and don't have any problem but web version on mobile devices have problem and show dark grey screen thank you for check and resolve it

i tried it with these flutter version :

2.0.0
2.0.1
2.0.2
2.0.3
2.0.4
2.0.5

Landscape crop area shape and portrait images - initial fit by height

Hello dear,
with forceInsideCropArea: true portrait images on init fits by height and not by width. If zoom in/out button pressed it is zoomed to fit width (as it should be). I found workaround how to solve it, but probably it can be implemented in initial logic.
// Delay and then zoom in the image to fit the width
Future.delayed(Duration(milliseconds: 100), () {
_croppController.addTransition(CropImageData(scale: 1.00001));

thanks!

CustomCropShape - Ratio

Is it possible to include a feature to use a ratio instead of the CustomCropShape? I'd need to be able to crop rectangles in custom ratios. If this package would support something like this, it would really be perfect.

Thanks

Add support for nullsafety

Because flutter 2.0 is now using dart 2.12 with stable nullsafety.

This package should be updated to be fully nullsafe

Add coverals support

Add support to see a badge on the readme page that shows how much test coverage we have for this project

Overlay color affects the Image

Hi,

I use this package. I select the image and display the image in the ShowDialog. However, the image is affected by overlay color.

Version: custom_image_crop: ^0.0.13

For your reference
image

Initial scaling

Is there a way to provide initial scaling? Or set the image to cover all the space it has?

onCropImage is not working as expected in web

I have implemented the plugin for handling the profile image crop and zoom functionality. If i select a new image and try to zoom in and do the crop, but it doesn't returned the cropped image.

Uint8List binaryImage = (await viewModel.cropController.onCropImage())?.bytes;

Add gifs to readme

Add a couple of gifs to show what the plugin actually does.

Right now you would have to runt he example project to see what is happening or how everyhing look.

apply crop on the initial image given by the input path

Great package, thanks for all the work.
Is it possible to apply the crop that the user has performed through the UI on the initial input image to get the output? I'm trying to find a way of not losing image resolution as a result of displaying the image for cropping in a small view.
I was thinking I can get the current transition/scale/rotation after the image is loaded and manipulated by the user, but I don't know how to get the initial mapping from the original image to the image initially loaded into the ui to be able to complete the pipeline of correctly applying the crop to the input image.

On a second thought, maybe that's already what you are doing in the package, but I might be using things incorrectly. Let me tell you about my setup. I have a 1920x1080 input image and my crop percentage is set to 1. I'm defining the rectangular crop area of 16x9, and I'm not zooming in or out or moving the image at all after loading. I'm also using CustomImageFit.fitCropSpace. I expect when I'm cropping the image without touching it, the output should be a 1920x1080 image but I'm getting a 1080x607 image.

Too slow cropping and result is too big

Trying to crop a 5Mb jpeg image leads to 10 secs. cropping process and the resulting file size if about 50Mb.
If I crom a small jpeg image (about 80Kb) then the process is fast but still have large output (about 1.7Mb).
It seems like the the library firs makes a raw bitmap then crops it and again returns an uncompressed bitmap.
Would be great if output file is compessed with the same format and quality as the input image.
And for sure cropping process itself should be speed up.

Crop bug if Ratio width < height

I tested with ratio: Ratio(width: 2, height: 3) and the cropped image does not match.
It works with square and width > height.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.