Project Description
high quality image resizing and cropping

source code here: https://github.com/omuleanu/imager

used in http://prodinner.codeplex.com (asp.net mvc sample app) for creating thumbnails
using Omu.Drawing;

cropping

Image img = Imager.Crop(sourceImage, new Rectangle(x, y, width, height));

resizing

Image img = Imager.Resize(sourceImage, newWidth, maxHeight, onlyResizeIfWider);

save

Imager.Save(path, img, Imager.GetEncoderInfo("image/gif"));
//image/gif is the MIME type for gif

save as jpeg

Imager.SaveJpeg(path, img);

put on canvas

the image remains the same size, and it is placed in the middle of the new canvas
Imager.PutOnWhiteCanvas(img, width, height))
// or
Imager.PutOnCanvas(img, width, height, Color.White))

example of usage in asp.net mvc with jquery plugin jcrop

        [OutputCache(Location = OutputCacheLocation.None)]
        public ActionResult Crop(CropDisplay cropDisplay)
        {
            return View(cropDisplay);
        }

        [HttpPost]
        [OutputCache(Location = OutputCacheLocation.None)]
        public ActionResult Crop(int x, int y, int w, int h)
        {
            using (var image = Image.FromFile(@ConfigurationManager.AppSettings["storagePath"] + @"\Temp\" + User.Identity.Name + ".jpg"))
            {
                var img = Imager.Crop(image, new Rectangle(x, y, w, h));
                var resized = Imager.Resize(img, 200, 150, true);
                Imager.SaveJpeg(@ConfigurationManager.AppSettings["storagePath"] + @"\Profile\" + User.Identity.Name + ".jpg", resized);
            }
            return RedirectToAction("Index");
        }

Last edited May 10 at 8:17 AM by o, version 13