• Stars
    star
    207
  • Rank 189,127 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A uGUI based image cropping solution for Unity 3D

Unity Image Cropper

screenshot

Available on Asset Store: https://assetstore.unity.com/packages/tools/gui/image-cropper-116650

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

Discord: https://discord.gg/UJJt549AaV

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

GitHub Sponsors โ˜•

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.

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

INSTALLATION

There are 5 ways to install this plugin:

  • import ImageCropper.unitypackage via Assets-Import Package
  • clone/download this repository and move the Plugins folder to your Unity project's Assets folder
  • import it from Asset Store
  • (via Package Manager) add the following line to Packages/manifest.json:
    • "com.yasirkula.imagecropper": "https://github.com/yasirkula/UnityImageCropper.git",
  • (via OpenUPM) after installing openupm-cli, run the following command:
    • openupm add com.yasirkula.imagecropper

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.

NOTE: Crop camera uses Layer 22 to render the thumbnails. On URP, make sure that that layer is included in the Layer Masks of the Forward Renderer asset.

EXAMPLE CODE

See ImageCropperDemo.cs.

More Repositories

1

UnityIngameDebugConsole

A uGUI based console to see debug messages and execute commands during gameplay in Unity
C#
2,117
star
2

UnityAssetUsageDetector

Find usages of the selected asset(s) and/or Object(s) in your Unity project, i.e. list the objects that refer to them
C#
1,693
star
3

UnityRuntimeInspector

Runtime Inspector and Hierarchy solution for Unity for debugging and runtime editing purposes
C#
1,676
star
4

UnityNativeGallery

A native Unity plugin to interact with Gallery/Photos on Android & iOS (save and/or load images/videos)
Objective-C++
1,396
star
5

UnityBezierSolution

A bezier spline solution for Unity 3D with some utility functions (like travelling the spline with constant speed/time)
C#
1,153
star
6

UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
C#
905
star
7

UnitySimpleFileBrowser

A uGUI based runtime file browser for Unity 3D (draggable and resizable)
C#
844
star
8

UnityDynamicPanels

Draggable, resizable, dockable and stackable UI panel solution for Unity 3D
C#
735
star
9

UnityNativeCamera

A native Unity plugin to take pictures/record videos with device camera on Android & iOS
C#
605
star
10

UnityRuntimePreviewGenerator

Generate preview textures (thumbnails) for your GameObject's or materials on the fly in Unity
C#
304
star
11

UnityNativeFilePicker

A native Unity plugin to import/export files from/to various document providers on Android & iOS
C#
277
star
12

UnityInspectPlus

Speeding up your Inspector workflow in Unity 3D
C#
254
star
13

UnityAndroidRuntimePermissions

A native Unity plugin to handle runtime permissions on Android M+
C#
194
star
14

UnityRuntimeSceneGizmo

Interactable runtime scene gizmo for uGUI
C#
175
star
15

UnitySimplePatchTool

Unity port of SimplePatchTool library to add patching support to standalone Unity applications
C#
163
star
16

UnitySimpleInput

An improvement over Unity's legacy Input system that allows you to use custom input providers like on-screen joysticks, UI buttons and d-pads
C#
157
star
17

UnityAdjustPivot

Adjust pivot point of an object in Unity without creating an empty parent object
C#
149
star
18

Unity360ScreenshotCapture

A simple script to capture 360ยฐ screenshots in-game with Unity
C#
142
star
19

SimplePatchTool

C# library for patching standalone applications with binary diff and self patching support
C#
132
star
20

UnityTextToTextMeshProUpgradeTool

Upgrade Text, InputField, Dropdown and TextMesh objects to their TextMesh Pro variants in Unity
C#
113
star
21

DownloadLinkGeneratorForGoogleDrive

Create list of files and their download links in a Google Driveโ„ข folder
HTML
109
star
22

UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
Objective-C++
104
star
23

UnityMobileLocalizedAppTitle

Localize your Unity app's name and/or icon on Android & iOS
C#
102
star
24

UnityGridFramework

Open source Grid Framework for creating grid-based levels easily in Unity 3D
C#
94
star
25

UnitySimpleGDPRConsent

A Unity plugin to present GDPR consent dialogs to the users
C#
93
star
26

UnityTextureOps

A basic image processing plugin for Unity
C#
87
star
27

UnityChoiceOfGamesSaveManager

Save manager for 'Choice of Games' on Steam - Created with Unity 3D
C#
76
star
28

UnitySpeechToText

A native Unity plugin to convert speech to text on Android & iOS
C#
70
star
29

UnityRuntimeTexture

An abstraction layer on top of Texture2D.LoadImage to create Texture2D objects at runtime from raw PNG/JPEG data in Unity
C#
62
star
30

UnityDashedSpriteShape

Creating dashed (dotted) 2D Sprite Shapes in Unity
ShaderLab
62
star
31

UnityMobileRemoteControl

Control your Windows device from your phone
C#
59
star
32

UnityEditorGoogleDriveIntegration

Access your Google Driveโ„ข files from within Unity editor
C#
48
star
33

UnityHexicGame

Hexic puzzle game made with Unity 3D
ShaderLab
36
star
34

UnityGenericPool

A simple generic pooling script for Unity3D with a helper class
C#
36
star
35

UnitySpinningLoadingBars

3 different spinning loading bar prefabs for Unity's UI system
28
star
36

UnityFlatColorPalettes

A number of flat color palettes for Unity 3D
26
star
37

UnityEveryplaySaveToLocal

A helper script to save captured Everyplay videos to local file system on Android & iOS
Objective-C++
15
star
38

UnityOrderedUpdate

Receive Update callback(s) from anywhere and in any order in Unity!
C#
15
star
39

UnityAndroidStreamingAssets

A helper script to extract StreamingAssets to local file system on Unity Android
C#
10
star
40

DownloadLinkGeneratorForDropbox

Create list of files and their download links in a Dropbox folder
HTML
6
star
41

SecondHand

Global Game Jam entry
C#
5
star
42

GeometricSketchpadProject

Bilkent CS102 Course Project
Java
4
star
43

GreenHellMods

A number of mods created via ModAPI for Green Hell game
C#
4
star
44

.github

Default GitHub community health files for all my repositories
2
star
45

BubblesProject

Bilkent CS319 Course Project
Java
2
star