0

I am using image magick for .net to cropping and resizing the images. But the problem with the library is that it only crop the bottom of the image. Isn't there any way by means which we can crop it evenly from both up and down or left and right?

Edited question :

  MagickGeometry size = new MagickGeometry(width, height);
  size.IgnoreAspectRatio = maintainAspectRatio;
  imgStream.Crop(size);
dlemstra
  • 7,813
  • 2
  • 27
  • 43
Naresh
  • 5,073
  • 12
  • 67
  • 124

2 Answers2

4

Crop will always use the specified width and height in Magick.NET/ImageMagick so there is no need to set size.IgnoreAspectRatio. If you want to cut out a specific area in the center of your image you should use another overload of Crop that also has a Gravity as an argument:

imgStream.Crop(width, height, Gravity.Center);
dlemstra
  • 7,813
  • 2
  • 27
  • 43
  • can you please also help me with this problem also http://stackoverflow.com/questions/31701190/apply-watermark-on-image-using-imagemagick-net-in-c-sharp – Naresh Jul 30 '15 at 06:26
2

If the size variable is an instance of MagickGeometry, than there should be an X & Y offset property. I'm not familiar with , but I would imagine it would be something like...

MagickGeometry size = new MagickGeometry(width, height);
size.IgnoreAspectRatio = maintainAspectRatio;
// Adjust geometry offset to center of image (same as `-gravity Center`)
size.Y = imgStream.Height / 2 - height / 2;
size.X = imgStream.Width / 2 - width / 2;
imgStream.Crop(size);
emcconville
  • 23,800
  • 4
  • 50
  • 66