SoundInTheory.Piranha.MediaExtensions.Images
4.11.0
dotnet add package SoundInTheory.Piranha.MediaExtensions.Images --version 4.11.0
NuGet\Install-Package SoundInTheory.Piranha.MediaExtensions.Images -Version 4.11.0
<PackageReference Include="SoundInTheory.Piranha.MediaExtensions.Images" Version="4.11.0" />
<PackageVersion Include="SoundInTheory.Piranha.MediaExtensions.Images" Version="4.11.0" />
<PackageReference Include="SoundInTheory.Piranha.MediaExtensions.Images" />
paket add SoundInTheory.Piranha.MediaExtensions.Images --version 4.11.0
#r "nuget: SoundInTheory.Piranha.MediaExtensions.Images, 4.11.0"
#:package SoundInTheory.Piranha.MediaExtensions.Images@4.11.0
#addin nuget:?package=SoundInTheory.Piranha.MediaExtensions.Images&version=4.11.0
#tool nuget:?package=SoundInTheory.Piranha.MediaExtensions.Images&version=4.11.0
Piranha Media Extensions
Various enhancements to Piranha CMS media
Cropped Image Field
An image field that allows multiple crops on a single image.
Only filesystem storage supported for now.
Supports cropping settings and multiple crops.
//In Piranha WebApplicationBuilder...
options.UseCroppedImageField();
//etc
//In PiranhaApplicationBuilder
options.UseCroppedImageField();
//etc
Then configure in Piranha content/model/etc
[Field, CroppedImageFieldSettings(AspectRatio = 16d / 9d, MinWidth = 100, MinHeight = 100, Crops = new string[] { "Default", "Second Crop" })]
public CroppedImageField TestImageFieldWithSettings { get; set; }
[Field]
public CroppedImageField TestImageFieldWithoutSettings { get; set; }
Image Sharp Providers
Providers and resolvers for ImageSharp.Web
There is both a provider for Piranha Media and limited support for Remote Images as well.
Simply configure the services before the AddPiranha call. The middleware is inserted into the
pipeline automatically, so there is nothing to add in UsePiranha.
//Before builder.AddPiranha(...)
builder.Services.UseImageSharpWeb(o =>
{
//Root path the Piranha media provider matches on (default "/image")
o.RootName = "/image";
})
.AddRemoteImageProvider(o =>
{
//A whitelist is necessary as it prevents any hijacking of your endpoint
o.WhiteList = [
"upload.wikimedia.org"
//etc
];
});
Images are then served from /image/{mediaId}?width=600&height=400, and remote images from
/remote/{url}.
Automatic WebP conversion
AddWebpConversion makes images served through the middleware come back as WebP without the caller
having to append ?format=webp to every URL. Typical saving is 25-65% on JPEG sources.
builder.Services.UseImageSharpWeb()
.AddWebpConversion(o =>
{
o.Quality = 80;
});
It works by injecting an autowebp command during command parsing, which is picked up by
AutoWebpWebProcessor after the image has been decoded. Deciding after the decode means the real
source format is known, so sources that must not be converted are excluded reliably.
| Option | Default | Description |
|---|---|---|
Enabled |
true |
Switch conversion off without changing wiring. |
Roots |
(empty) | Path prefixes to convert. When empty, only the Piranha media root is converted. |
Quality |
75 |
WebP quality (1-100). Below 100 forces lossy encoding. |
ConfigureEncoder |
null |
Further customisation of the WebpEncoder (Method, FileFormat, NearLossless, ...). |
ExcludedFormats |
{ "GIF" } |
Source formats never converted, by IImageFormat.Name. |
AutoOrient |
true |
Also inject autoorient, so EXIF rotation is applied before the resize. |
OverrideExplicitFormat |
false |
Whether to override a ?format= supplied on the request. |
ShouldConvert |
null |
Final per-request say on whether to convert. |
Per request, ?autowebp=false opts out and an explicit ?format=jpg still wins.
GIF is excluded because ImageSharp 2.1 has no animated WebP encoder - converting an animated GIF
would silently flatten it to its first frame. There is a second guard in the processor that leaves any
multi-frame image alone even if ExcludedFormats is cleared.
Note that the remote provider is ProcessingBehavior.CommandOnly, so adding its root to Roots means
every remote URL gets decoded and re-encoded rather than passing straight through.
Before you enable it
- Clear the ImageSharp cache (
wwwroot/is-cacheby default). Every URL gains commands, so every cache key changes and the old entries are orphaned rather than reused. /image/{mediaId}with no query stops being a byte copy - it now decodes and re-encodes. Cold cache CPU goes up, bytes served go down.- URLs keep no file extension while the payload is WebP. Browsers honour the
Content-Type, but tooling that infers the type from the URL will guess wrong. autoorientchanges output geometry for EXIF-rotated sources. A portrait phone photo requested at?width=600currently comes back 600px tall (the browser rotates it on display); with auto-orient it comes back 600px wide. SetAutoOrient = falseto keep the old geometry.- PNG sources become lossy WebP at the default quality. For flat-colour graphics, raise
Qualityor useConfigureEncoderwithFileFormat = WebpFileFormatType.Lossless. - Do not route SVG through
/image- SVG is not an ImageSharp format, so those requests fail regardless of this feature. Usemedia.PublicUrlinstead.
Gallery Field
Field that supports multiple images
//In Piranha WebApplicationBuilder...
options.UseGalleryField();
//etc
//In PiranhaApplicationBuilder
options.UseGalleryField();
//etc
Then configure in Piranha content/model/etc
[Field]
public GalleryField TestGalleryField { get; set; }
//In your view/wherever you want to access
foreach(var image in TestGalleryField.Images){
//Use as if it's a normal image field.
}
Extended Media Manager
Supports filtering and ordering on both mediapicker and media views.
//In Piranha WebApplicationBuilder...
options.UseMediaManager();
//etc
//In PiranhaApplicationBuilder
options.UseMediaManager();
//etc
Examples are provided in repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Piranha (>= 10.4.0)
- Piranha.AspNetCore (>= 10.4.0)
- Piranha.Local.FileStorage (>= 10.4.0)
- Piranha.Manager (>= 10.4.0)
- SixLabors.ImageSharp (>= 2.1.10)
- SixLabors.ImageSharp.Web (>= 2.0.2)
-
net7.0
- Piranha (>= 10.4.0)
- Piranha.AspNetCore (>= 10.4.0)
- Piranha.Local.FileStorage (>= 10.4.0)
- Piranha.Manager (>= 10.4.0)
- SixLabors.ImageSharp (>= 2.1.10)
- SixLabors.ImageSharp.Web (>= 2.0.2)
-
net8.0
- Piranha (>= 12.0.0)
- Piranha.AspNetCore (>= 12.0.0)
- Piranha.Local.FileStorage (>= 12.0.0)
- Piranha.Manager (>= 12.0.0)
- SixLabors.ImageSharp (>= 2.1.10)
- SixLabors.ImageSharp.Web (>= 2.0.2)
-
net9.0
- Piranha (>= 12.0.0)
- Piranha.AspNetCore (>= 12.0.0)
- Piranha.Local.FileStorage (>= 12.0.0)
- Piranha.Manager (>= 12.0.0)
- SixLabors.ImageSharp (>= 2.1.10)
- SixLabors.ImageSharp.Web (>= 2.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.11.0 | 160 | 8/14/2026 |
| 4.9.0 | 178 | 7/15/2026 |
| 4.8.1 | 110 | 7/14/2026 |
| 4.8.0 | 173 | 6/15/2026 |
| 4.7.0 | 115 | 6/15/2026 |
| 4.6.0 | 115 | 6/15/2026 |
| 4.5.0 | 337 | 4/14/2026 |
| 4.4.1 | 152 | 2/19/2026 |
| 4.4.0 | 650 | 11/19/2025 |
| 4.3.0 | 458 | 11/19/2025 |
| 4.2.0 | 400 | 11/17/2025 |
| 4.1.0 | 394 | 11/17/2025 |
| 4.0.0 | 246 | 11/7/2025 |
| 3.2.0 | 299 | 10/24/2025 |
| 3.1.0 | 323 | 6/5/2025 |
| 3.0.1 | 500 | 4/30/2025 |
| 3.0.0 | 266 | 4/3/2025 |
| 2.0.1 | 471 | 7/4/2024 |
| 1.0.3 | 396 | 4/18/2024 |
| 1.0.2 | 288 | 4/15/2024 |