This project has moved and is read-only. For the latest updates, please go here.

Padding out Thumbnails

Mar 25, 2014 at 6:22 PM
Original Image: 600px wide by 1000px tall (PNG format)

Let's say I want to resize the above image down to 108px by 108px. Obviously looking at my original image, the image would be distorted if I had it fill this 'thumbnail' version.

If I use the MagickImage.Resize(100, 100) command, this works great but the end image size is roughly 108 x 65. What I truly want is for the remaining space to be transparent, centering the original image into the resized 100 x 100 image.

Looking at the Magick documentation, it appears the "Pad Out the Thumbnail" section would fit the bill:

I just can't figure out how it should be written in C# .NET
Mar 25, 2014 at 7:15 PM
You are looking for the Extent method:
using (MagickImage image = new MagickImage(Color.Yellow, 600, 1000))
  image.Resize(100, 100);
  image.BackgroundColor = MagickColor.Transparent;
  image.Extent(100, 100, Gravity.Center);
Mar 25, 2014 at 7:37 PM
Jackpot, exactly what I was looking for, thanks!