https://github.com/geta/imagesharp.processing.autocrop
Auto cropping for ImageSharp
https://github.com/geta/imagesharp.processing.autocrop
Last synced: 5 months ago
JSON representation
Auto cropping for ImageSharp
- Host: GitHub
- URL: https://github.com/geta/imagesharp.processing.autocrop
- Owner: Geta
- License: other
- Created: 2021-05-13T23:15:12.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-10-10T15:20:06.000Z (over 2 years ago)
- Last Synced: 2024-03-19T01:00:59.461Z (about 1 year ago)
- Language: C#
- Size: 2.52 MB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ImageSharp.Processing.AutoCrop
## Description
Automatic cropping for images with a flat background.
Works with SixLabors.ImageSharp 2.0.0 and above.Uses a relative luminance tolerance to determine which area to crop.
## Features
- Crops images with a flat background
- Configurable x and y padding
- Configurable treshold## How to get started?
### ImageSharp.Web integration
Requires SixLabors.ImageSharp 2.0.0 or above
- `install-package ImageSharp.Web.AutoCrop`
The namespace `ImageSharp.Web.AutoCrop.Extensions` contains some useful extensions to `SixLabors.ImageSharp.Web.DependencyInjection.IImageSharpBuilder`
#### In Startup.cs
Make sure to call the extension `AddAutoCropProcessor` when adding ImageSharp to services, that's all.
```
public void ConfigureServices(IServiceCollection services)
{
services.AddImageSharp()
.AddAutoCropProcessor();
...
}public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Configure ImageSharp.Web
app.UseImageSharp();
...
}
```Check out the [demo](docs/demo.md) for some examples.
Check out the [demo project](src/ImageSharp.Web.AutoCrop.Demo) for the full source.### Plain AutoCrop
Requires SixLabors.ImageSharp 2.0.0 or above
- `install-package ImageSharp.Processing.AutoCrop`
The namespace `ImageSharp.Processing.AutoCrop.Extensions` contains some useful extensions to `SixLabors.ImageSharp.Processing.IImageProcessingContext`
```
using var image = Image.Load("image.png");image.Mutate(ctx => ctx.AutoCrop());
```Check the different overloads for some options.
## Details
The underlying `AutoCropProcessor` that will handle the actual cropping takes some parameters.
| Parameter | Description | Default value |
| --------------- | ------------------------------------------------------------------------------------------------ | ------------- |
| PadX | How much horizontal whitespace in percent (0-100) to apply outside the crop | 0 |
| PadY | How much vertical whitespace in percent (0-100) to apply outside the crop | 0 |
| PadMode | Determines if padding should be allowed to expand outside the original image (Expand or Contain) | Expand |
| ColorThreshold | Color divergence to tolerate from analyzed border color (0-255) | 35 |
| BucketThreshold | How many percent of the border that has to belong to the most present color bucket (0.0f-1.0f) | 0.945f |## How it works

## Package maintainer
https://github.com/svenrog
## Changelog
[Changelog](CHANGELOG.md)