-
Notifications
You must be signed in to change notification settings - Fork 62
Description
The padding Color.Transparent is inconsistent between the two methods:
using var outStreamF_PNG = new FileStream(StorePathFile_PNG, FileMode.OpenOrCreate);
var padSettings_PNG = new ProcessImageSettings { EncoderOptions = new PngEncoderOptions { Filter = PngFilter.Adaptive } };
MagicImageProcessor.BuildPipeline(mStream_PNG, padSettings_PNG).AddTransform(new PadTransform(System.Drawing.Color.Transparent, padTop, padRight, padBottom, padLeft)).WriteOutput(outStreamF_PNG);
Despite the instruction of System.Drawing.Color.Transparent, the padded area is rendered as white.
Whereas setting the ProcessImageSettings with MatteColor = System.Drawing.Color.Transparent will produce a transparent padded area around the image.
ProcessImageSettings processImgSettings = new()
{
HybridMode = HybridScaleMode.FavorQuality,
Width = destF.MaxWidth,
Height = destF.MaxHeight,
Sharpen = true,
ResizeMode = CropScaleMode.Pad,
MatteColor = System.Drawing.Color.Transparent
};
processImgSettings.EncoderOptions = new PngEncoderOptions { Filter = PngFilter.Adaptive };
MagicImageProcessor.ProcessImage(btArr, StorePathFile_PNG, processImgSettings);
I noticed that the documentation for PadTransform says "Adds solid-colored padding pixels to an image." But why would this not honor System.Drawing.Color.Transparent when padding a png image?
When we process images that are larger than the target size, the ProcessImageSettings with CropScaleMod.Pad works perfectly.
But when the source image is smaller than the target size we have to calculate the padding for each side and apply the PadTransform. This is where it fails us. A cropscale mode for padding with the option to not upscale the image would be ideal, but would gladly settle for a solution where the PadTransform option works with Color.Transparent.