Jack
Jack

Reputation: 9242

ImageResizer auto scale down

We've implemented the base server for ImageResizer, but we have one more requirement. We are dealing with user uploaded images. Sometimes users want to upload 5MB, 10MB, even 30MB images (some are from surveillance footage and this is expected). But we don't want to store the full image size when over a certain threshold. I'm no imaging expert - maybe we should use the client ImageResizer API and set the dpi, or maxwidth/maxheight? What is the best practice for scaling down image size?

Look at FileContentLength and do a ?maxwidth=1000&maxheight=1000 if over some specified size?

Look at the width/height of the image and scale down accordingly? Currently ImageResizer has no way to "Get" image dimensions.

I have seen this post, but we don't want to do this on our thumbnail (150x150) images obviously.

Upvotes: 0

Views: 102

Answers (1)

Lilith River
Lilith River

Reputation: 16468

Do you care about file size or type/resolution? If the former, just do

if (post.FileContentLength > MAX_SIZE){ 
  //Use ImageResizer
}else{
  //store as-is
}

Otherwise, always use ImageResizer and specify &maxwidth=3200&maxheight=3200.

If you're worried about storage or bandwidth, then file size might be sufficient.

The downside to leaving files as-is: Metadata will be retained, and corrupted or non-web-friendly image formats will stay web-unfriendly. Very high resolution images can sometimes compress to very tiny file sizes; there's no linear correlation, so if your consumers (like mobile devices) crash on high-megapixel images, then you could have a problem.

The upsize to leaving files as-is: Users may have already optimized their images, so you won't make it 'worse'. Metadata will be retained (if that's a good thing).

Usually we suggest only modifying uploading images prior to storage for file size reasons, and then re-compressing all images using the ImageResizer URL API and Slimmage.js to ensure clients get an appropriate image for their device.

Upvotes: 1

Related Questions