Image transformations are available trough services implementing OpenWaves.ImageTransformations.IImageTransformationService. The default implementation of the service (GdiImageTransformationService) uses System.Drawing namespace to transform input images. An
instance of the service can be created manually (new GdiImageTransformationService()) or resolved using
or another dependency resolution strategy.
The interface has a single method:
public interface IImageTransformationService
void TransformImage(Stream input, Stream output, ImageFormat outputFormat, IImageTransformation transformation);
ImageFormat enumeration determines the format of the image written to the output stream. Currently supported are Jpeg and Png.
IImageTransformation is currently implemented by a set of classes from OpenWaves.ImageTransformation namespace. All transformations can be serialized to string using ToString() method and later deserialized using ImageTransformation.Parse() method.
- resizes an image so it fits specified rectangle (width/height) without clipping. For example when fitting into a square, landscape images will be sized so their width matches the width of the square, while portrait images will
be sized so their height matches the height of the square. This is the most often used transformation (galleries, thumbnails, user pictures, or whenever you want to avoid clipping the image).
- same as the above but will only resize an image if it is larger then specified rectangle (width/height). This is for example useful if you want to scale images for display on mobile device, where any image wider then the
width of the screen gets scaled down, but the ones that fit the display are not transformed.
- resizes an image so it fills the whole rectangle (width/height). Ultimately the image is scaled so it is large enough to cover the target area and centrally cropped to match the specified dimensions. Useful when a graphics
design assumes that the picture covers the whole region of a page.
The following code shows how to scale "input.jpg" using ScaleToFit transformation, so it fits 100x100 rectangle. The result is written to "output.jpg".
var service = ServiceLocator.Resolve<IImageTransformationService>();
using (var input = File.OpenRead(@"input.jpg"))
using (var output = File.Create(@"output.jpg"))
service.TransformImage(input, output, ImageFormat.Jpeg, new ScaleToFitTransformation(100, 100));
Windows Server 2012 Server Core mode
To use OW Image Transformations, WindowsCodecsExt.dll is required. Windows 2012 in Server Core mode DOES NOT have this dll installed in neither System32 nor SysWOW64 directory. Fortunately it can be found on the machine and copied to following localizations:
%system root%\System32\WindowsCodecsExt.dll -64bit dll version
%system root%\SysWOW64\WindowsCodecsExt.dll - 32bit dll version