Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

crop_your_image

a flutter plugin which provides crop widget for cropping images.

crop_your_image provides only minimum ui for deciding cropping area inside images. other ui parts, such as “crop” button or “change aspect ratio” button, need to be prepared by each app developers.

this policy helps app developers to build “cropping page” with the design of their own brand.in order to control the actions for cropping images, you can use cropcontroller from whatever your widgets.

cropyourimage

features

  • minimum ui restrictions.
  • flexible crop widget which can be placed anywhere on your widget tree.
  • cropcontroller to control crop actions.
  • crop with both rect and circle
  • fix aspect ratio.
  • set the rect of cropping area programmatically.

note that this package don’t

  • read / download image data from any storages, such as gallery, internet, etc.
  • resize, tilt, or other conversions which can be done with image package directly.
  • provide ui parts other than cropping editor, such as “crop” button, “preview” button or “change aspect ratio” menu. building ui is completely up to you!

note

please note that this package is at the very starting point of developping. i’m always waiting for your feedbacks and pull requests for making crop_your_image more handy and useful with less bugs.

usage

basics

place crop widget wherever you want to place image cropping ui.

final _controller = cropcontroller();

widget build(buildcontext context) {
  return crop(
    image: _imagedata,
    controller: _controller,
    oncropped: (image) {
      // do something with image data 
    }
  );
}

then, crop widget will automatically display cropping editor ui on users screen with given image.

by creating a cropcontroller instance and pass it to controller property of crop, you can controll the crop widget from your own designed widgets.

for example, when you want to crop the image with current selected cropping area, you can just call _controller.crop() wherever you want, such like the code below.

elevatedbutton(
  child: text('crop it!')
  onpressed: _cropcontroller.crop,
),

because _controller.crop() only kicks the cropping process, this method returns immediately without any cropped image data. you can always obtain the result of cropping images via oncropped callback of crop widget.

advanced

all the properties of crop and their usages are below.

final _controller = cropcontroller();

widget build(buildcontext context) {
  return crop(
    image: _imagedata,
    controller: _controller,
    oncropped: (image) {
      // do something with image data 
    },
    aspectratio: 4 / 3,
    initialsize: 0.5,
    // initialarea: rect.fromltwh(240, 212, 800, 600),
    // withcircleui: true,
    basecolor: colors.blue.shade900,
    maskcolor: colors.white.withalpha(100),
    onmoved: (newrect) {
      // do something with current cropping area.
    }
    cornerdotbuilder: (size, cornerindex) => const dotcontrol(color: colors.blue),
  );
}
  • image is image data whose type is uint8list, and the result of cropping can be obtained via oncropped callback.
  • aspectratio is the aspect ratio of cropping area. set null or just omit if you want to crop images with any aspect ratio.
  • aspectratio can be changed dynamically via setter of cropcontroller.aspectratio. (see below)
  • initialsize is the initial size of cropping area. 1.0 (or null, by default) fits the size of image, which means cropping area extends as much as possible. 0.5 would be the half. this value is also referred when aspectratio changes via cropcontroller.aspectratio.
  • initialarea is the initial rect of cropping area based on actual image data.
  • withcircleui flag is to decide the shape of cropping ui. if true, aspectratio is automatically set 1.0 and the shape of cropping ui would be circle. note that this flag does not affect to the result of cropping image. if you want cropped images with circle shape, call cropcontroller.cropcircle instead of cropcontroller.crop.
  • basecolor is the color of the mask widget which is placed over the cropping editor.
  • maskcolor is the color of the base color of the cropping editor.
  • onmoved callback is called when cropping area is moved regardless of its reasons. newrect of argument is current rect of cropping area.
  • cornerdotbuilder is the builder to build widget placed at corners. the builder passes size which widget must follow and cornerindex which indicates the position: 0: left-top, 1: right-top, 2: left-bottom, 3: right-bottom.

in addition, image, aspectratio, withcircleui, rect and area can also be changed via cropcontroller, and other properties, such as basecolor, maskcolor and cornerdotbuilder, can be changed by setstate.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.