Images increase heavily in size after uploading

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hello,

Iv'e noticed that images, such as product images and others, are increasing in size immensely after uploading them. For instance, I uploaded a 30Kb image as a product image. The size of the image had increased to 121Kb when I tried to download the image via a browser. This happens with all photos.

Does anybody know if this is a bug, and if not how might I fix this problem?

I would sincerely appreciate any help.
7 years ago
Does anybody know how to deal with this issue?
7 years ago
danlev wrote:
Does anybody know how to deal with this issue?

All uploaded images get passed through the ValidatePicture function in PictureService.cs which uses the ImageResizer library to compress the image and save it to either the file system or database. There are a couple of easily accessible settings under Media Settings in nop that affect this file size of the resulting image:

1. Maximum image size (default 1980) constrains the longest image size and resizes the image proportionally
2. Default image quality (0 - 100) (default 80) determines the amount of compression that is applied to the resulting image (higher number = higher quality = less compression)

Andrei has previously asked about this on Stack Overflow and received an answer from the author of the ImageResizer library, though that mainly covers png images not jpegs.

I think if your jpeg is heavily compressed before you upload it to nop then it can lead to it being re-encoded with less compression. Obviously it's not possible for this process to improve the image quality but it can lead to an increase in file size.

One possible way to prevent this might be to change the ValidatePicture function to only re-encode images on upload if it results in a smaller file size than the original (alteration in bold):

public virtual byte[] ValidatePicture(byte[] pictureBinary, string mimeType)
{
    using (var destStream = new MemoryStream())
    {
        ImageBuilder.Current.Build(pictureBinary, destStream, new ResizeSettings
        {
            MaxWidth = _mediaSettings.MaximumImageSize,
            MaxHeight = _mediaSettings.MaximumImageSize,
            Quality = _mediaSettings.DefaultImageQuality
        });                
        return (destStream.Length < pictureBinary.Length) ? destStream.ToArray() : pictureBinary;
    }
}

(though this is then potentially bypassing the MaximumImageSize constraint)
7 years ago
Hello there. You have a web address called Optimizilla, you can reduce the size of the images you optimize, for example 1 mb reduces the image by 100 kB
7 years ago
I know this is an old topic but did anyone find the source of this problem. It looks to me like the Imageresizer changes the DPI or colour settings which triples the size of the file. I've highlighted in another post that this causes a major issue running on SQL Azure.

I've built a TinyPNG plugin that will shrink all pictures as they are added to nop but if the picture is pushed through Imageresizer again I will have the same problem. I'm running nop 3.7. It's not even as if the resizer is dependency injected so I can use something else.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.