{"id":15008610,"url":"https://github.com/lykhonis/image_crop","last_synced_at":"2025-04-04T15:09:15.084Z","repository":{"id":37417697,"uuid":"151986018","full_name":"lykhonis/image_crop","owner":"lykhonis","description":"A flutter plugin to crop image on iOS and Android.","archived":false,"fork":false,"pushed_at":"2024-07-08T09:47:34.000Z","size":13065,"stargazers_count":328,"open_issues_count":58,"forks_count":229,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-28T14:06:52.752Z","etag":null,"topics":["dart","dart-lang","flutter","image-manipulation"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lykhonis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"VolodymyrLykhonis"}},"created_at":"2018-10-07T21:14:34.000Z","updated_at":"2025-03-06T14:02:01.000Z","dependencies_parsed_at":"2023-01-31T05:30:28.475Z","dependency_job_id":"83d246de-bd18-4c55-b912-126ad7d984f3","html_url":"https://github.com/lykhonis/image_crop","commit_stats":null,"previous_names":["volodymyrlykhonis/image_crop"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2Fimage_crop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2Fimage_crop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2Fimage_crop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2Fimage_crop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lykhonis","download_url":"https://codeload.github.com/lykhonis/image_crop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198461,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dart-lang","flutter","image-manipulation"],"created_at":"2024-09-24T19:19:41.427Z","updated_at":"2025-04-04T15:09:15.062Z","avatar_url":"https://github.com/lykhonis.png","language":"Dart","funding_links":["https://github.com/sponsors/VolodymyrLykhonis"],"categories":[],"sub_categories":[],"readme":"# Image Cropping plugin for Flutter\n\nA flutter plugin to crop image on iOS and Android.\n\n![Image Cropping Preview](assets/image_cropping_preview.gif)\n\nThe plugin comes with a `Crop` widget. The widget renders only image, overlay, and handles to crop an image. Thus it can be composed with other widgets to build custom image cropping experience. \n\nThe plugin is working with files to avoid passing large amount of data through method channels. Files are stored in cache folders of iOS and Android. Thus if there is a need to save actual cropped image, ensure to copy the file to other location.\n\nAll of the computation intensive work is done off a main thread via dispatch queues on iOS and cache thread pool on Android.\n\n*Note*: This plugin is still under development, some features are not available yet and testing has been limited.\n\n## Installation\nAdd `image_crop` [![image_crop](https://img.shields.io/pub/v/image_crop.svg)](https://pub.dartlang.org/packages/image_crop) as [a dependency in `pubspec.yaml`](https://flutter.io/using-packages/#managing-package-dependencies--versions).\n\n## Using\nCreate a widget to load and edit an image:\n```dart\nfinal cropKey = GlobalKey\u003cCropState\u003e();\n\nWidget _buildCropImage() {\n  return Container(\n      color: Colors.black,\n      padding: const EdgeInsets.all(20.0),\n      child: Crop(\n        key: cropKey,\n        image: Image.file(imageFile),\n        aspectRatio: 4.0 / 3.0,\n      ),\n  );\n}\n```\nAccess cropping values:\n- scale is a factor to proportionally scale image's width and height when cropped. `1.0` is no scale needed.\n- area is a rectangle indicating fractional positions on the image to crop from.\n```dart\nfinal crop = cropKey.currentState;\n// or\n// final crop = Crop.of(context);\nfinal scale = crop.scale;\nfinal area = crop.area;\n\nif (area == null) {\n    // cannot crop, widget is not setup\n    // ...\n}\n```\nAccessing and working with images. As a convenience function to request permissions to access photos.\n```dart\nfinal permissionsGranted = await ImageCrop.requestPermissions();\n``` \nRead image options, such as: width and height. This is efficient implementation that does not decode nor load actual image into a memory.\n```dart\nfinal options = await getImageOptions(file: file);\ndebugPrint('image width: ${options.width}, height: ${options.height}');\n```\nIf a large image is to be loaded into the memory, there is a sampling function that relies on a native platform to proportionally scale down the image before loading it to the memory. e.g. resample image to get down to `1024x4096` dimension as close as possible. If it is a square `preferredSize` can be used to specify both width and height. Prefer to leverage this functionality when displaying images in UI.\n```dart\nfinal sampleFile = await ImageCrop.sampleImage(\n    file: originalFile,\n    preferredWidth: 1024,\n    preferredHeight: 4096,\n);\n```\nOnce `Crop` widget is ready, there is a native support of cropping and scaling an image. In order to produce higher quality cropped image, rely on sampling image with preferred maximum width and height. Scale up a resolution of the sampled image. When cropped, the image is in higher resolution. Example is illustrated below:\n```dart\nfinal sampledFile = await ImageCrop.sampleImage(\n    file: originalFile,\n    preferredWidth: (1024 / crop.scale).round(),\n    preferredHeight: (4096 / crop.scale).round(),\n);\n\nfinal croppedFile = await ImageCrop.cropImage(\n    file: sampledFile,\n    area: crop.area,\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykhonis%2Fimage_crop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flykhonis%2Fimage_crop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykhonis%2Fimage_crop/lists"}