NopCommerce: Image size constraints

225 views Asked by At

Using NopComm 3.90.

Is there a way in NopComm to set an image size constraint?

In Config -> Settings -> Media Settings, I can set the size of the images, but from what I gather this is setting default sizes of images? I need to set a hard constraint on the image sizes that our publishers will have to abide by. Thanks.

1

There are 1 answers

0
Raphael On BEST ANSWER

If you are using default picture upload in admin panel this method gets triggered during picture insert

/// <summary>
/// Validates input picture dimensions
/// </summary>
/// <param name="pictureBinary">Picture binary</param>
/// <param name="mimeType">MIME type</param>
/// <returns>Picture binary or throws an exception</returns>
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.ToArray();
    }
}

If you set "MaximumImageSize" in media settings nopCommerce will auto resize large images.

Setting a constraint to enforce a specific minimum picture size does not exists. But you could easily create a plugin for that.