Merge pull request #3177 from sbwalker/dev
add support for background color padding during image resizing
This commit is contained in:
commit
a327358b7a
|
@ -679,6 +679,25 @@ 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);
|
||||||
|
|
||||||
|
PngEncoder encoder;
|
||||||
|
|
||||||
|
if (background != "transparent")
|
||||||
|
{
|
||||||
|
image.Mutate(x => x
|
||||||
|
.AutoOrient() // auto orient the image
|
||||||
|
.Rotate(angle)
|
||||||
|
.Resize(new ResizeOptions
|
||||||
|
{
|
||||||
|
Mode = resizemode,
|
||||||
|
Position = anchorpositionmode,
|
||||||
|
Size = new Size(width, height),
|
||||||
|
PadColor = Color.ParseHex("#" + background)
|
||||||
|
}));
|
||||||
|
|
||||||
|
encoder = new PngEncoder();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
image.Mutate(x => x
|
image.Mutate(x => x
|
||||||
.AutoOrient() // auto orient the image
|
.AutoOrient() // auto orient the image
|
||||||
.Rotate(angle)
|
.Rotate(angle)
|
||||||
|
@ -689,19 +708,14 @@ namespace Oqtane.Controllers
|
||||||
Size = new Size(width, height)
|
Size = new Size(width, height)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (background != "transparent")
|
encoder = new PngEncoder
|
||||||
{
|
|
||||||
image.Mutate(x => x
|
|
||||||
.BackgroundColor(Color.ParseHex("#" + background)));
|
|
||||||
}
|
|
||||||
|
|
||||||
PngEncoder encoder = new PngEncoder
|
|
||||||
{
|
{
|
||||||
ColorType = PngColorType.RgbWithAlpha,
|
ColorType = PngColorType.RgbWithAlpha,
|
||||||
TransparentColorMode = PngTransparentColorMode.Preserve,
|
TransparentColorMode = PngTransparentColorMode.Preserve,
|
||||||
BitDepth = PngBitDepth.Bit8,
|
BitDepth = PngBitDepth.Bit8,
|
||||||
CompressionLevel = PngCompressionLevel.BestSpeed
|
CompressionLevel = PngCompressionLevel.BestSpeed
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
image.Save(imagepath, encoder);
|
image.Save(imagepath, encoder);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user