-
Notifications
You must be signed in to change notification settings - Fork 1
Imaging
theonlylawislove edited this page Feb 18, 2013
·
22 revisions
The layout builder is responsible for building the canvas/image dimensions based on some parameters.
- Width/Height
- MaxWidth/MaxHeight
- Mode - How to resolve aspect ratio differences between the requested size and the original image's size.
- Anchor - Determines where the image will be anchored if there is padding or cropping. The default is "middleCenter".
-
Scale - Controls whether the image is allowed to upscale, downscale, both, or if only the canvas gets to be upscaled.
- scale=down - The default. Only downsamples images - never enlarges. If an image is smaller than 'width' and 'height', the image coordinates are used instead.
- scale=up - Only upscales (zooms) images - never downsamples. If an image is larger than 'width' and 'height', the image coordinates are used instead.
- scale=both - Upscales and downscales images according to 'width' and 'height'.
- scale=canvas - When the image is smaller than the requested size, padding is added instead of stretching the image.
Based on these values, you will get an ImageLayout object that contains the canvas size and the destination of the image (floating rectangle).
Separating the layout building of the image from the actual re-sizing allows use to reuse this logic on problems such as PDF building.
IImageLayoutBuilder imageLayoutBuilder = Noodle.EngineContext.Resolve<IImageLayoutBuilder>();
var sourceSize = new Size(100, 150);
var resizeSettings = new ResizeSettings("width=200&height=200&mode=fit");
var layout = imageLayoutBuilder.BuildLayout(sourceSize, resizeSettings);
The image manipulator will re-size an actual image using the logic contained in the IImageManipulator. The result is a Bitmap object that can be with as you please.
IImageManipulator imageManipulator = Noodle.EngineContext.Resolve<IImageManipulator>();
var resized = imageManipulator.Resize("c:\image.jpg", new ResizeSettings("width=200&height=200&mode=fit"));