|
| 1 | +# Image Cropper PCF Control |
| 2 | + |
| 3 | +A Power Apps Component Framework (PCF) control for cropping, rotating, and transforming images, built with React and designed for robust, modular, and Power Apps-compliant use. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +The Image Cropper control provides a modern, accessible, and highly configurable image cropping experience for both Model-driven and Canvas Power Apps. It supports aspect ratio locking, scaling, rotation, circular/elliptical cropping, and advanced browser scaling handling. The control is built with React functional components and custom hooks for maintainability and extensibility. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- Crop images with drag-and-resize UI |
| 14 | +- Lock aspect ratio or allow freeform cropping |
| 15 | +- Rotate and scale images |
| 16 | +- Circular/elliptical crop support |
| 17 | +- Handles browser and container scaling |
| 18 | +- Default crop values from manifest |
| 19 | +- Robust image load and crop state management |
| 20 | +- Outputs cropped image as base64 PNG |
| 21 | +- Fully modular React hooks architecture |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +[Download Latest](https://github.com/rwilson504/PCFControls/releases/latest/download/ImageCropperControl_managed.zip) |
| 26 | + |
| 27 | +Import the managed solution into your environment. |
| 28 | +Ensure PCF controls are enabled. [Enable PCF](https://docs.microsoft.com/en-us/powerapps/developer/component-framework/component-framework-for-canvas-apps) |
| 29 | + |
| 30 | +## Sample Application |
| 31 | + |
| 32 | +A sample solution is available for testing and demonstration: |
| 33 | + |
| 34 | +[Download Sample App](./Sample/RAW!%20ImageCropper%20Sample.msapp) |
| 35 | + |
| 36 | +## Configuration |
| 37 | + |
| 38 | +Add the Image Cropper control to your form or app and configure the required properties. |
| 39 | +**Any field referenced in the properties must be present in your view or data source.** |
| 40 | + |
| 41 | +### Control Properties |
| 42 | + |
| 43 | +| Name | Usage | Type | Required | Default | Description | |
| 44 | +|---------------------|----------|------------------|----------|---------|------------------------------------------------------------------| |
| 45 | +| imageInput | input | SingleLine.Text | Yes | | Image source (base64 or URL) | |
| 46 | +| aspect | input | Decimal Number | No | 0 | Aspect ratio (width/height), blank for freeform | |
| 47 | +| minWidth | input | Whole.Number | No | -1 | Minimum crop width | |
| 48 | +| maxWidth | input | Whole.Number | No | -1 | Maximum crop width | |
| 49 | +| minHeight | input | Whole.Number | No | -1 | Minimum crop height | |
| 50 | +| maxHeight | input | Whole.Number | No | -1 | Maximum crop height | |
| 51 | +| rotation | input | Whole.Number | No | 0 | Image rotation in degrees | |
| 52 | +| scaling | input | Decimal Number | No | 1 | Image scaling factor | |
| 53 | +| circularCrop | input | TwoOptions | No | false | Enable circular/elliptical crop | |
| 54 | +| keepSelection | input | TwoOptions | No | false | Keep crop selection after crop | |
| 55 | +| locked | input | TwoOptions | No | false | Lock crop area (disable editing) | |
| 56 | +| disabled | input | TwoOptions | No | false | Disable the control | |
| 57 | +| ruleOfThirds | input | TwoOptions | No | false | Show rule-of-thirds grid | |
| 58 | +| DefaultUnit | input | OptionSet | No | % | Default crop unit (px or %) | |
| 59 | +| DefaultX | input | Whole.Number | No | -1 | Default crop X position | |
| 60 | +| DefaultY | input | Whole.Number | No | -1 | Default crop Y position | |
| 61 | +| DefaultWidth | input | Whole.Number | No | -1 | Default crop width | |
| 62 | +| DefaultHeight | input | Whole.Number | No | -1 | Default crop height | |
| 63 | + |
| 64 | +### Output Properties |
| 65 | + |
| 66 | +| Name | Type | Description | |
| 67 | +|--------------|----------------|---------------------------------------------| |
| 68 | +| croppedImage | SingleLine.Text| Cropped image as base64 PNG (data URL) | |
| 69 | + |
| 70 | +## Advanced Usage |
| 71 | + |
| 72 | +- All crop, aspect, and transform logic is modularized in custom React hooks for maintainability. |
| 73 | +- The control automatically handles browser scaling, image load timing, and crop validity. |
| 74 | +- Circular/elliptical cropping uses canvas ellipse masking for true round crops. |
| 75 | +- Default crop values are only applied after the image is loaded. |
| 76 | + |
| 77 | +## Resources |
| 78 | + |
| 79 | +- [PCF Documentation](https://docs.microsoft.com/en-us/powerapps/developer/component-framework/overview) |
| 80 | +- [react-image-crop](https://github.com/dominictarr/react-image-crop) |
| 81 | +- [PCF Controls Repo](https://github.com/rwilson504/PCFControls) |
0 commit comments