Giter Site home page Giter Site logo

unityimagecropper's Introduction

Unity Image Cropper

screenshot

Available on Asset Store: https://www.assetstore.unity3d.com/en/#!/content/116650

Forum Thread: https://forum.unity.com/threads/released-image-cropper-multiplatform-image-cropping-solution-with-oval-mask-support.526901/

WebGL Demo: http://yasirkula.net/ImageCropperDemo/

A. ABOUT

ImageCropper aims to be a powerful, customizable and easy-to-use image cropping solution for Unity 3D. It is created with Unity's UI system.

B. FEATURES

  • Supports rectangular and oval cropping modes
  • Supports auto-zoom feature for fine-tuning the selection
  • Costs 1 SetPass call and 6 batches (assuming that Sprite Packing is enabled in Editor Settings)
  • Can work on pretty much any screen resolution/orientation

C. HOW TO

ImageCropper is a singleton object that can be accessed via ImageCropper.Instance. To start cropping a Texture object, you can call the following function:

ImageCropper.Instance.Show( Texture image, CropResult onCrop, Settings settings = null, ImageResizePolicy croppedImageResizePolicy = null )

  • image: the Texture object to crop
  • onCrop: callback that will be invoked after cropping is finished/cancelled. Its signature is as following: void CropResult( bool result, Texture originalImage, Texture2D croppedImage ). result stores whether the image is cropped successfully or operation is cancelled, originalImage stores the Texture passed as image parameter and croppedImage stores the resulting cropped image
  • croppedImageResizePolicy: called before the cropped image is saved as Texture2D. Can be used to override the size of the Texture2D object. Its signature is as following: void ImageResizePolicy( ref int width, ref int height ), where width and height will initially be equal to the dimensions of the selection (crop area). If left null, texture's size will be equal to the selection's size. Can be used to e.g. always output a 256x256 Texture2D
  • settings: can be used to adjust the parameters of the image cropper. Available parameters are:
    • bool autoZoomEnabled (default=true): if enabled, image cropper will zoom in to the selection (crop area) if it is too small, and zoom out if selection is too large
    • bool pixelPerfectSelection (default=false): if enabled, selection's position and size values will be rounded to the nearest integers. As a RenderTexture with a render camera is used to generate the cropped image (instead of reading the pixels of the source image), a pixel perfect selection doesn't really have a big impact on the output
    • bool ovalSelection (default=false): if enabled, an oval mask will be used to crop the image in oval/circular shape. Otherwise, image will be cropped in rectangular/square shape
    • bool markTextureNonReadable (default=true): marks the cropped texture as non-readable for better memory usage. If you plan to modify the texture later (e.g. GetPixels/SetPixels), set its value to false
    • Color imageBackground (default=black): determines the background color of the cropped image. Background color will be visible if source image has transparency or if ovalSelection is enabled. For a completely transparent background, set its value to Color.clear (which has 0 alpha). Note that if imageBackground is opaque (alpha=1), cropped texture will be in RGB24 format instead of RGBA32 format. As RGB24 uses less memory, try not to use a transparent background color unless it is needed
    • Button visibleButtons (default=FlipHorizontal|FlipVertical|Rotate90Degrees): determines which image orientation buttons will be visible in the user interface. By default, all buttons are visible
    • Visibility guidelinesVisibility (default=AlwaysVisible): determines the visibility of the selection guidelines. Accepted values are: Hidden, OnDrag (only visible while the selection is being dragged/resized) and AlwaysVisible
    • Orientation initialOrientation (defaul=Normal): initial orientation (flipped/rotated state) of the image. Please see EXIF orientations before changing its value: http://sylvana.net/jpegcrop/exif_orientation.html
    • Vector2 selectionMinSize (default=0,0): minimum size of the selection (crop area). If untouched, it will be equal to 1/10th of the source image's size
    • Vector2 selectionMaxSize (default=0,0): maximum size of the selection (crop area). If untouched, there will be no limit
    • float selectionMinAspectRatio (default=0): minimum aspect ratio of the selection (crop area). If untouched, there will be no limit
    • float selectionMaxAspectRatio (default=0): maximum aspect ratio of the selection (crop area). If untouched, there will be no limit. For a circular/square selection, you can set both selectionMinAspectRatio and selectionMaxAspectRatio to 1
    • float selectionInitialPaddingLeft (default=0.1): initial padding-left of the selection in %
    • float selectionInitialPaddingTop (default=0.1): initial padding-top of the selection in %
    • float selectionInitialPaddingRight (default=0.1): initial padding-right of the selection in %
    • float selectionInitialPaddingBottom (default=0.1): initial padding-bottom of the selection in %

NOTE: before calling the Show function, you may want to check the value of ImageCropper.Instance.IsOpen to make sure that the image cropper is not already visible.

D. EXAMPLE CODE

See ImageCropperDemo.cs.

unityimagecropper's People

Contributors

yasirkula avatar

Watchers

James Cloos avatar

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.