Image Class

Summary

This module manipulates images by applying a variety of operations.
Assembly
Wyam.Images.dll
Namespace
Wyam.Images
Interfaces
Base Types
  • Object
graph BT Type-->Base0["Object"] Type-.->Interface0["IModule"] click Interface0 "/api/Wyam.Common.Modules/IModule" Type["Image"] class Type type-node

Syntax

public class Image : IModule

Remarks

This module manipulates images by applying operations such as resizing, darken/lighten, etc. This image module does not modify your original images in any way. It will create a copy of your images and produce images in the same image format as the original. It relies on other modules such as ReadFiles to read the actual images as input and WriteFiles to write images to disk.

Pipelines.Add("Images",
  ReadFiles("*")
    .Where(x => new[] { ".jpg", ".jpeg", ".gif", ".png"}.Contains(x.Path.Extension)),
  Image()
    .SetJpegQuality(100).Resize(400,209).SetSuffix("-thumb"),
  WriteFiles("*")
);

It will produce image with similar file name as the original image with addition of suffix indicating operations that have performed, e.g. "hello-world.jpg" can result in "hello-world-w100.jpg". The module allows you to perform more than one set of processing instructions by using the fluent property And.

Pipelines.Add("Images",
  ReadFiles("*")
    .Where(x => new[] { ".jpg", ".jpeg", ".gif", ".png"}.Contains(x.Path.Extension)),
  Image()
    .SetJpegQuality(100).Resize(400, 209).SetSuffix("-thumb")
    .And()
    .SetJpegQuality(70).Resize(400*2, 209*2).SetSuffix("-medium"),
  WriteFiles("*")
);

The above configuration produces two set of new images, one with a "-thumb" suffix and the other with a "-medium" suffix.

Constructors

Name Summary
Image() Process images in the content of the input document.

Methods

Name Value Summary
And() Image
Mark the beginning of another set of processing instructions to be applied to the images.
BlackWhite() Image
Applies black and white toning to the image.
Brightness(float) Image
Brightens the image.
Contrast(float) Image
Adjusts the contrast of the image.
Execute(IReadOnlyList<IDocument>, IExecutionContext) IEnumerable<IDocument>
This should not be called directly, instead call IExecutionContext.Execute() if you need to execute a module from within another module.
Hue(float) Image
Sets the hue of the image using 0 to 360 degree values.
Opacity(float) Image
Multiplies the alpha component of the image.
Operation(Func<IImageProcessingContext, IImageProcessingContext>, Func<FilePath, FilePath>) Image
Allows you to specify your own ImageSharp operation.
OutputAs(Action<Image, Stream>, Func<FilePath, FilePath>) Image
Allows you to specify an alternate output format for the image. For example, you might use this if you want to full specify the encoder and it's properties. This will override the default behavior of outputting the image as the same format.
OutputAsBmp() Image
Outputs the image as BMP. This will override the default behavior of outputting the image as the same format.
OutputAsGif() Image
Outputs the image as GIF. This will override the default behavior of outputting the image as the same format.
OutputAsJpeg() Image
Outputs the image as JPEG. This will override the default behavior of outputting the image as the same format.
OutputAsPng() Image
Outputs the image as PNG. This will override the default behavior of outputting the image as the same format.
Resize(Nullable<int>, Nullable<int>, AnchorPositionMode, ResizeMode) Image
Resizes the image to a certain width and height. No resizing will be performed if both width and height are set to null.
Saturate(float) Image
Saturates the image.
SetPrefix(string) Image
Set the prefix of the generated image, e.g. SetPrefix("medium-") will transform original filename "hello-world.jpg" to "medium-hello-world.jpg".
SetSuffix(string) Image
Set the suffix of the generated image, e.g. SetSuffix("-medium") will transform original filename "hello-world.jpg" to "hello-world-medium.jpg".
Vignette(Rgba32) Image
Apply vignette processing to the image with specific color, e.g. Vignette(Rgba32.AliceBlue).
GitHub