It sounds like you don't actually need to physically resize the image (as you want to maintain the same size for it), but instead you want to losslessly compress it. Loseless compression will attempt to optimize the image and reduce it's size without
actually changing the size of the image. Additionally, you could even likely use lossy compression and set the quality to a percentage like 70-90% in order to see how the size differs.
These functions are generally not going to be best implemented using built-in functions and you'll be better off using a library. I would recommend trying the
ImageMagick library out, which I believe is available via
a NuGet package. Basically, just install this package to your Project and then use it as follows :
// Open your image using the ImageMagick library (after adding it through NuGet)
MagickImage img = new MagickImage(file.InputStream);
// Adjust your width, if necessary
if(img.Width > 1000)
{
img.Resize(1000, 1000);
}
// Attempt to resize the size (adjust this to get an idea of how it works)
img.Quality = 60; // Default is 75
img.Write("path");
Sherwin, I don't think your post answers the original question. The question was not how to resize in dimension but how to result to smaller size in MB.
Member
327 Points
1770 Posts
How to resize an uploaded image
Sep 28, 2014 06:46 AM|grafic.web|LINK
Hi, i would love to resize my image, but i don't know if is possible to do this with no fixed value like the example :
But make the image under 1,5 MB with proportion, without whanging the hight and lenght..
For example; i found this whay to cheka how muche is big the photo :
With this code, do i get the size in MB?
AND AFTER..
But how to resize it? kepping same hight and lenght but lower MB dimension (max 1,5 MB)
All-Star
114593 Points
18503 Posts
MVP
Re: How to resize an uploaded image
Sep 28, 2014 09:06 AM|Rion Williams|LINK
It sounds like you don't actually need to physically resize the image (as you want to maintain the same size for it), but instead you want to losslessly compress it. Loseless compression will attempt to optimize the image and reduce it's size without actually changing the size of the image. Additionally, you could even likely use lossy compression and set the quality to a percentage like 70-90% in order to see how the size differs.
These functions are generally not going to be best implemented using built-in functions and you'll be better off using a library. I would recommend trying the ImageMagick library out, which I believe is available via a NuGet package. Basically, just install this package to your Project and then use it as follows :
Participant
1882 Points
290 Posts
Re: How to resize an uploaded image
Mar 06, 2015 04:26 AM|Sherwin Zhao|LINK
Hi,
For you post, please try the following code, there are 4 kinds of resize.
Hope this can be helpful to you.
Sherwin Zhao
Best Regards
All-Star
35149 Points
9075 Posts
Re: How to resize an uploaded image
Mar 06, 2015 05:40 AM|smirnov|LINK
Sherwin, I don't think your post answers the original question. The question was not how to resize in dimension but how to result to smaller size in MB.