Merge pull request #3177 from sbwalker/dev

add support for background color padding during image resizing
This commit is contained in:
Shaun Walker 2023-08-23 10:05:46 -04:00 committed by GitHub
commit a327358b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -679,29 +679,43 @@ namespace Oqtane.Controllers
Enum.TryParse(mode, true, out ResizeMode resizemode); Enum.TryParse(mode, true, out ResizeMode resizemode);
Enum.TryParse(position, true, out AnchorPositionMode anchorpositionmode); Enum.TryParse(position, true, out AnchorPositionMode anchorpositionmode);
image.Mutate(x => x PngEncoder encoder;
.AutoOrient() // auto orient the image
.Rotate(angle)
.Resize(new ResizeOptions
{
Mode = resizemode,
Position = anchorpositionmode,
Size = new Size(width, height)
}));
if (background != "transparent") if (background != "transparent")
{ {
image.Mutate(x => x image.Mutate(x => x
.BackgroundColor(Color.ParseHex("#" + background))); .AutoOrient() // auto orient the image
} .Rotate(angle)
.Resize(new ResizeOptions
{
Mode = resizemode,
Position = anchorpositionmode,
Size = new Size(width, height),
PadColor = Color.ParseHex("#" + background)
}));
PngEncoder encoder = new PngEncoder encoder = new PngEncoder();
}
else
{ {
ColorType = PngColorType.RgbWithAlpha, image.Mutate(x => x
TransparentColorMode = PngTransparentColorMode.Preserve, .AutoOrient() // auto orient the image
BitDepth = PngBitDepth.Bit8, .Rotate(angle)
CompressionLevel = PngCompressionLevel.BestSpeed .Resize(new ResizeOptions
}; {
Mode = resizemode,
Position = anchorpositionmode,
Size = new Size(width, height)
}));
encoder = new PngEncoder
{
ColorType = PngColorType.RgbWithAlpha,
TransparentColorMode = PngTransparentColorMode.Preserve,
BitDepth = PngBitDepth.Bit8,
CompressionLevel = PngCompressionLevel.BestSpeed
};
}
image.Save(imagepath, encoder); image.Save(imagepath, encoder);
} }