---
title: "Transforming Images with Pipelines"
canonical: https://www.graphicsmill.com/docs/gm/transforming-images-with-pipelines.htm
product: "Graphics Mill"
---

# Transforming Images with Pipelines
 
This article helps you to understand how to use the major Graphics Mill transforms with the pipeline syntax. We will not learn all the aspects of the transforms here and we presume that you are already familiar with them. If not, please review how to [use the transforms with the regular syntax](https://www.graphicsmill.com/docs/gm/transformations-on-images.htm.md) first. Here are the sections we are going to cover with this article:
 
- resizing and cropping
- rotating and flipping
- overlaying images
- converting colors

## Resizing and Cropping
  
### Resizing
 
The main parameters for the resize transform are width and height of resulting images. If you want Graphics Mill to preserve the aspect ratio of the image, you should specify only one dimension. Resize quality and speed depends on specified interpolation mode. Better quality means lower speed. The [ResizeInterpolationMode](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeInterpolationMode.htm.md) enumeration exposes all available interpolation modes.
 
The following code proportionally resizes images to 2048 pixel width:
 
```csharp
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var resize = new Resize(2048, 0, ResizeInterpolationMode.High))
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
    Pipeline.Run(reader + resize + writer);
}
```
 
### Cropping
 
Cropping requires you to pass a crop rectangle as an input parameter. The rectangle can be set as four **System.Int32** values: x and y coordinates of the upper left rectangle corner, rectangle width, and rectangle height. Or you can set the rectangle as a [Rectangle](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.rectangle?view=netframework-4.8) instance.
 
The following code crops 50x100 rectangle out of the image and saves the result in JPEG format:
 
```csharp
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var crop = new Crop(50, 60, 50, 100))
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
    Pipeline.Run(reader + crop + writer);
}
```
 
## Rotating and Flipping
  
### Rotating
 
In Graphics Mill positive degree numbers cause clockwise rotation and negative degree numbers cause counter-clockwise rotation. A special cases are rotation by 90, 180, or 270 degrees, because it uses a special algorithm which avoids floating-point calculations yielding to higher performance. In these cases you get the rotated version of the source image without additional background. In other cases the rotated image will have margins, filled with background color, making it rectangular.
 
If you do not specify a background color and an interpolation mode, the transparent white color and the high quality interpolation mode are used. Rotation quality and speed depend on the specified interpolation mode. Better quality means lower speed. The [InterpolationMode](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_InterpolationMode.htm.md) enumeration exposes the available interpolation modes.
 
You can specify a background color and an interpolation mode as the [constructor](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Transforms_Rotate_ctor.htm.md) arguments or through the [Rotate.BackgroundColor](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Rotate_BackgroundColor.htm.md) and Rotate.[Rotate.InterpolationMode](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Rotate_InterpolationMode.htm.md) properties.
 
The following code rotates an image by 5 degrees clockwise using the [Bitmap.Transforms](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Transforms.htm.md) property:
 
```csharp
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var rotate = new Rotate(5, RgbColor.Yellow, InterpolationMode.High))
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
    Pipeline.Run(reader + rotate + writer);
}
```
 
### Flipping
 
To flip an image you have to specify one of the following flip types: [Horizontal](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_FlipType.htm.md), **Vertical**, or **Both**.
 
The following code flips an image horizontally:
 
```csharp
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var flip = new Flip(FlipType.Horizontal))
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
    Pipeline.Run(reader + flip + writer);
}
```
 
## Overlaying Images
  
Graphics Mill provides features for combining images, including watermarking and masked overlaying (collages). You may select one of many available combine modes and set the foreground image coordinates.
 
To watermark an image you should configure the [Combiner](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Combiner.htm.md) as follows:
 
1. Set the [Combiner.Mode](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Combiner_Mode.htm.md) property to [Alpha](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_CombineMode.htm.md).
2. Prepare an overlay image and pass it to the [Combiner.TopImage](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Combiner_TopImage.htm.md) property. This property allows you not to load the whole image to memory as it accepts [Pipeline](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Pipeline.htm.md). In our sample we read an image from a file and make it semitransparent.
3. Position an overlay image via [Combiner.X](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Combiner_X.htm.md) and [Combiner.Y](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Combiner_Y.htm.md) properties.

```csharp
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var watermark = new PngReader(@"Images\watermark.png"))
using (var combiner = new Combiner())
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
    var overlay = new Pipeline();
    overlay.Add(watermark);
    overlay.Add(new ScaleAlpha(0.8f));
    
    combiner.Mode = CombineMode.Alpha;
    combiner.TopImage = overlay;
    combiner.X = 10;
    combiner.Y = reader.Height - watermark.Height - 40;
    combiner.AutoDisposeTopImage = true;

    Pipeline.Run(reader + combiner + writer);
}
```
 
## Converting Colors
  
Converting pixels between different color spaces, you can choose whether to apply color management. If you do not use color management, it works faster, but conversion is inaccurate. Colors may look non-realistic. On the other hand, color management allows preserving natural colors, but it slower. To choose the color management engine, use the [ColorConverter.ColorManagementEngine](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_ColorConverter_ColorManagementEngine.htm.md) property. When it is [LittleCms](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ColorManagementEngine.htm.md) or **AdobeCmm**, color management is enabled, if **None** - disabled. Also, color management can be successfully used only if [input and output profiles](https://www.graphicsmill.com/docs/gm/converting-color-with-color-management.htm.md) are provided.
 
To convert image colors from RGB to CMYK you need to specify the color profile of the CMYK color space (which corresponds to the device where we want to display this image, for example your printer). The following code demonstrates color conversion with **Euroscale Coated** profile.
 
```csharp
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var converter = new ColorConverter(PixelFormat.Format32bppCmyk))
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
    converter.ColorManagementEngine = ColorManagementEngine.LittleCms;
    converter.DestinationProfile = new ColorProfile(
        @"C:\windows\system32\spool\drivers\color\EuroscaleCoated.icc");
    Pipeline.Run(reader + converter + writer);
}
```
 
## See Also
  
### Reference
 
- [Resize Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Resize.htm.md)
- [ResizeMode Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeMode.htm.md)
- [ResizeInterpolationMode Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeInterpolationMode.htm.md)
- [Crop Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Crop.htm.md)
- [Rotate Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Rotate.htm.md)
- [Flip Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Flip.htm.md)
- [Combiner Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Combiner.htm.md)
- [ColorConverter Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ColorConverter.htm.md)

### Manual
 
- [Resizing and Cropping Images](https://www.graphicsmill.com/docs/gm/resizing-and-cropping-images.htm.md)
- [Rotating and Flipping Images](https://www.graphicsmill.com/docs/gm/rotating-and-flipping-images.htm.md)
- [Overlaying Images](https://www.graphicsmill.com/docs/gm/overlaying-images-advanced-drawing.htm.md)
- [Combine Modes](https://www.graphicsmill.com/docs/gm/combine-modes.htm.md)
- [Converting Colors with Color Management](https://www.graphicsmill.com/docs/gm/converting-color-with-color-management.htm.md)
