|
|
|
@ -1,7 +1,6 @@ |
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.Primitives; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Processing |
|
|
|
@ -20,6 +19,17 @@ namespace SixLabors.ImageSharp.Processing |
|
|
|
/// <param name="height">The new height.</param>
|
|
|
|
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
|
|
|
|
public static IImageProcessingContext Pad(this IImageProcessingContext source, int width, int height) |
|
|
|
=> source.Pad(width, height, default); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Evenly pads an image to fit the new dimensions with the given background color.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="source">The source image to pad.</param>
|
|
|
|
/// <param name="width">The new width.</param>
|
|
|
|
/// <param name="height">The new height.</param>
|
|
|
|
/// <param name="color">The background color with which to pad the image.</param>
|
|
|
|
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
|
|
|
|
public static IImageProcessingContext Pad(this IImageProcessingContext source, int width, int height, Color color) |
|
|
|
{ |
|
|
|
var options = new ResizeOptions |
|
|
|
{ |
|
|
|
@ -28,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing |
|
|
|
Sampler = KnownResamplers.NearestNeighbor, |
|
|
|
}; |
|
|
|
|
|
|
|
return source.Resize(options); |
|
|
|
return color.Equals(default) ? source.Resize(options) : source.Resize(options).BackgroundColor(color); |
|
|
|
} |
|
|
|
} |
|
|
|
} |