Image Wyam.Images

This module manipulates images by applying a variety of operations.

This module manipulates images by applying operations such as resizing, darken/lighten, etc. This image module does not modify your original images in anyway.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.

Package

This module exists in the Wyam.Images package which is not part of the core distribution. Add the following preprocessor directive to your configuration file to use it:
#n Wyam.Images
Alternativly, you can add all modules at once with the following preprocessor directive:
#n Wyam.All

Usage

  • Image()

    Creates the module without any instructions.

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • ApplyFilters(params ImageFilter[] filters)

    Applies the the specified image filters. The available filters are:

    • ImageFilter.BlackAndWhite
    • ImageFilter.Comic
    • ImageFilter.Gotham
    • ImageFilter.GreyScale
    • ImageFilter.HiSatch
    • ImageFilter.Invert
    • ImageFilter.Lomograph
    • ImageFilter.LoSatch
    • ImageFilter.Polaroid
    • ImageFilter.Sepia
    These filter values map directly to filters provided by ImageProcessor library. You can see the effects of these filters here.

    • filters

      The filters to apply.

  • Brighten(short percentage)

    Brightens the image by the specified percentage.

    • percentage

      The percentage to brighten the image by (0 to 100).

  • Constrain(int width, int height)

    Constrains the image to a specified size. If the image is larger than the specified width and height, it will be resized down. If the image is smaller than the specified width and height, it will not be resized.

    • width

      The maximum desired width.

    • height

      The maximum desired height.

  • Darken(short percentage)

    Darkens the image by the specified percentage.

    • percentage

      The percentage to darken the image by (0 to 100).

  • Desaturate(short percentage)

    Desaturates the image.

    • percentage

      The desaturation percentage (0 to 100).

  • Resize(int? width, int? height, AnchorPosition anchor = Center)

    Resizes the image to a certain width and height. It will crop the image whenever necessary. The module will not perform any image resizing if both width and height are set to null. If the source image is smaller than the specified width and height, the image will be enlarged.

    • width

      The desired width. If set to null or 0, the image will be resized to its height.

    • height

      The desired height. If set to null or 0, the image will be resized to its width.

    • anchor

      The anchor position to use for cropping (if necessary). The available values are:

      • AnchorPosition.Center
      • AnchorPosition.Top
      • AnchorPosition.Bottom
      • AnchorPosition.Left
      • AnchorPosition.Right
      • AnchorPosition.TopLeft
      • AnchorPosition.TopRight
      • AnchorPosition.BottomLeft
      • AnchorPosition.BottomRight

  • Saturate(short percentage)

    Saturates the image.

    • percentage

      The saturation percentage (0 to 100).

  • SetContrast(short percentage)

    Adjusts the contrast of the image.

    • percentage

      Set the contrast value of the image from the value of -100 to 100.

  • SetHue(short degrees, bool rotate = false)

    Sets the hue of the image using 0 to 360 degree values.

    • degrees

      The degrees to set.

    • rotate

      If set to true, rotates the hue.

  • SetJpegQuality(short quality)

    This setting only applies to JPEG images. It sets the quality of the JPEG output. The possible values are from 0 to 100.

    • quality

      The desired JPEG quality (0 to 100).

  • SetOpacity(short percentage)

    Sets the opacity of the image.

    • percentage

      The opacity percentage (0 to 100).

  • SetPrefix(string prefix)

    Set the prefix of the generated image, e.g. SetPrefix("medium-") will transform original filename "hello-world.jpg" to "medium-hello-world.jpg".

    • prefix

      The prefix to use.

  • SetSuffix(string suffix)

    Set the suffix of the generated image, e.g. SetSuffix("-medium") will transform original filename "hello-world.jpg" to "hello-world-medium.jpg".

    • suffix

      The suffix to use.

  • Tint(Color color)

    Tints the image to the specified color, e.g. Color.Aqua. Please check here for more color values.

    • color

      The color to tint the image to.

  • Vignette(Color color)

    Apply vignette processing to the image with specific color, e.g. Vignette(Color.AliceBlue).

    • color

      The color to use for the vignette.

GitHub