I need a code that will allow me to resize images, but with the following functionality:
1) resize image upon upload
2) Resize image proportionally by specifying either height or width.
Note:
For example: The function should get the a width OR a height, and resize the image proportionally for the give height OR Width. Let's say that the image is 400(w)x100(h). I want to tell the function to resize the image to a specific height, let's say 80px. The function should resize the image proportionally while setting the image height to 80px and the width accordingly. Another option is ti tell the function the width, let's say 200px, and the function should resize the image to 200px width and set the height accordingly.
3) save the image to a specific location (path).
4) Function can work with uploaded image or by specifying an image path.
5) I want to be able to choose the image quality
6) Only need this for JPEG
Can somebody please help me out with this. Thanks.
Although it seems like you should be able to copy and paste a snippet to do this, there are a ton of pitfalls you need to look out for if you're building your own image resizing system. It's better to use a proven, tested, and supported open-source library.
To resize to a file directly from HttpPostedFile, call
ImageBuilder.Current.Build(httpPostedFile, "img.jpg", new ResizeSettings("width=200&quality=90"));
To resize an existing file, call
ImageBuilder.Current.Build("orig.jpg", "img.jpg", new ResizeSettings("width=200&quality=90"));
The ImageResizing.Net library is free, and MIT-licensed (no worries about licensing problems).