{"id":13478492,"url":"https://github.com/ritiek/auto-image-cropper","last_synced_at":"2025-03-21T21:31:43.247Z","repository":{"id":62438378,"uuid":"91608140","full_name":"ritiek/auto-image-cropper","owner":"ritiek","description":"Removes extra white borders to correctly resize canvas","archived":false,"fork":false,"pushed_at":"2020-08-15T20:45:23.000Z","size":2657,"stargazers_count":24,"open_issues_count":0,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-10T16:51:54.692Z","etag":null,"topics":["canvas","crop","image","resize","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ritiek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-17T18:31:45.000Z","updated_at":"2024-05-31T07:27:41.000Z","dependencies_parsed_at":"2022-11-01T21:49:57.292Z","dependency_job_id":null,"html_url":"https://github.com/ritiek/auto-image-cropper","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fauto-image-cropper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fauto-image-cropper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fauto-image-cropper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritiek%2Fauto-image-cropper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ritiek","download_url":"https://codeload.github.com/ritiek/auto-image-cropper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244164534,"owners_count":20408949,"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":["canvas","crop","image","resize","rust"],"created_at":"2024-07-31T16:01:57.802Z","updated_at":"2025-03-21T21:31:42.500Z","avatar_url":"https://github.com/ritiek.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# auto-image-cropper\n\n[![Crates.io](https://img.shields.io/crates/v/auto-image-cropper.svg)](https://crates.io/crates/auto-image-cropper/) [![Build Status](https://travis-ci.org/ritiek/auto-image-cropper.svg?branch=master)](https://travis-ci.org/ritiek/auto-image-cropper/)\n\n- Removes extra white boundaries from images to correctly resize canvas.\n\n- Thanks **[@matthewkmayer](https://github.com/matthewkmayer)** for bringing down cropping times\n  (see [#1](https://github.com/ritiek/auto-image-cropper/pull/1) and [#2](https://github.com/ritiek/auto-image-cropper/pull/2))!\n\n## Screenshots\n\nThe borders are just to represent the actual images tested with.\n(click to zoom)\n\n\u003cimg src=\"http://i.imgur.com/3pc600q.jpg\" width=\"240\"\u003e            \u003cimg src=\"http://i.imgur.com/nMR1ZuV.jpg\" width=\"200\"\u003e\n\n\u003cimg src=\"http://i.imgur.com/QIXGDCk.jpg\" width=\"270\"\u003e            \u003cimg src=\"http://i.imgur.com/NTfeN3e.jpg\" width=\"200\"\u003e\n\n## Installation and Usage\n\n```shell\n$ cargo install auto-image-cropper\n```\n\nor if you like to live on the bleeding edge\n\n```shell\n$ git clone https://github.com/Ritiek/auto-image-cropper\n$ cd auto-image-cropper\n$ cargo build --release\n```\n\nUse `./target/release/autocrop` to start using the tool.\n\n```shell\nUSAGE:\n    autocrop [OPTIONS] --input \u003cLOCATION\u003e\n\nFLAGS:\n    -h, --help       Prints help information\n    -V, --version    Prints version information\n\nOPTIONS:\n    -i, --input \u003cLOCATION\u003e     Location of input image/directory\n    -o, --output \u003cLOCATION\u003e    Location of output image/directory\n```\n\nFor example:\n```\n$ ./target/release/autocrop -i benchmarking/face.jpg -o face.out.jpg\n```\n\n## Python Bindings\n\nThis tool also provides Python bindings via [PyO3](https://github.com/PyO3/pyo3) (using Rust FFI).\n\nYou need a Rust nightly toolchain to proceed (PyO3 does not support Rust stable at the moment).\nIf you have `rustup`, run:\n```\n$ rustup default nightly\n```\nto switch to nightly channel.\n\nThis feature can then be enabled by passing `--features \"python-binding\"` to cargo when compiling.\n\nFor example:\n```shell\n$ cargo build --release --features \"python-binding\"\n```\n\nThis will generate a dynamic library (\\*.so) on Linux machines with the name\n`./target/release/libauto_image_cropper.so`.\n\nLet's move this dynamic library into our current working directory:\n```shell\n$ mv target/release/libauto_image_cropper.so .\n```\nIt can now be utilized via Python scripts using:\n```python\n\u003e\u003e\u003e import libauto_image_cropper\n\n# Returns the optimal top-left and bottom-right corner\n# coordinates for a given image to be cropped\n\u003e\u003e\u003e (top_left, bottom_right) = libauto_image_cropper.calculate_corners(\"benchmarking/face.jpg\")\n\u003e\u003e\u003e print(top_left)\n(442, 73)\n\u003e\u003e\u003e print(bottom_right)\n(783, 536)\n```\n(I haven't checked this out on Windows or OSX, but should follow a similar procedure)\n\n## Benchmarks\n\n- This tool was hackishly re-written in [Python](python/) to compare with Rust - just for fun.\n\n- The benchmarks were done on a MacBook Air running macOS Sierra 10.12.2.\n\n|                  Image                  |  Python |  Rust  | Times Faster |\n|:---------------------------------------:|:-------:|:------:|:------------:|\n| [face.jpg](benchmarking/face.jpg)       |  0.867s | 0.155s |         5.59 |\n| [square.png](benchmarking/square.png)   |  1.682s | 0.142s |        11.84 |\n| [flowers.jpg](benchmarking/flowers.jpg) |  2.222s | 0.476s |         4.66 |\n| [human.jpg](benchmarking/human.jpg)     |  2.362s | 0.294s |         8.02 |\n| [pets.jpg](benchmarking/pets.jpg)       |  5.366s | 1.704s |         3.14 |\n| [agent47.jpg](benchmarking/agent47.jpg) | 51.559s | 7.519s |         6.85 |\n\n- Python struggles to find the optimal coordinates but is quick (quicker than Rust) when saving the cropped image back to disk. Rust really outperforms while finding the optimal coordinates.\n\n**[2020 / 03] UPDATE:** These benchmarks were done in 2017. Rust and its image libraries have a come long way ahead and I\nbelieve should now offer even better performance! I'll update these benchmarks when I'm able to.\n\n## License\n\n`The MIT License`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritiek%2Fauto-image-cropper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fritiek%2Fauto-image-cropper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritiek%2Fauto-image-cropper/lists"}