0

I am looking for An ImageResizer Like below that supports MaxWidth & MaxHeight ...
where can i find it?
the below module does many other jobs that are not necessary for me.
just want to change format & support maxwidth and maxheight.

ImageResizer

BenMorel
  • 34,448
  • 50
  • 182
  • 322
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • http://stackoverflow.com/questions/249587/high-quality-image-scaling-c – Yochai Timmer May 19 '11 at 14:59
  • Version 3 of the module has a plugin architecture, so by default it only offers resizing and format conversion, plus a few other minor features. Extra stuff is added via 36+ plugins. It's also free, now, and you can download the source code from http://imageresizing.net/download. – Lilith River Oct 26 '11 at 15:01

2 Answers2

2

You can write a wrapper that enforces the maximum width and maximum height, and maintains the aspect ratio.

For example, say you have an image that's 640 x 120 and your maximums are 1,920 x 1,440. Now, you want to make that image as large as possible, so you write:

ResizeImage(image, 1920, 1440)

If you were to do that, the aspect ratio would be shot.

You need to compute the aspect ratio of the existing image and adjust the values.

// Compute existing aspect ratio
double aspectRatio = (double)image.Width / image.Height;

// Clip the desired values to the maximums
desiredHeight = Math.Min(desiredHeight, MaxHeight);
desiredWidth = Math.Min(desiredWidth, MaxWidth);

// This is the aspect ratio if you used the desired values.
double newAspect = (double)desiredWidth / desiredHeight;

if (newAspect > aspectRatio)
{
    // The new aspect ratio would make the image too tall.
    // Need to adjust the height.
    desiredHeight = (int)(desiredWidth / aspectRatio);
}
else if (newAspect < aspectRatio)
{
    // The new aspect ratio would make the image too wide.
    // Need to adjust the width.
    desiredWidth = (int)(desiredHeight * aspectRatio);
}

// You can now resize the image using desiredWidth and desiredHeight
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
1

It doesn't matter if the library does more than what you need. If it does what you need it to, use it. The extra stuff isn't going to impair you at all.

NerdFury
  • 18,876
  • 5
  • 38
  • 41
  • Version 3 of the module has a plugin architecture, so by default it only offers resizing and format conversion, plus a few other minor features. Extra stuff is added via 36+ plugins. It's also free, now, and you can download the source code from http://imageresizing.net/download. – Lilith River Oct 26 '11 at 15:02