Web Forms upload guides
Validate Image Dimensions Before an ASP.NET Upload
A profile photo that is 80 pixels wide will look bad when it is shown at 200 pixels, and a 12,000-pixel scan may exhaust memory when the server resizes it. File size alone does not catch either problem. Checking the pixel dimensions before the transfer starts tells the user what to fix.
Enable the dimension check
Set EnableImageDimensions="true" and the minimum and maximum width and height. The browser reads the image header, so an image outside the range never uploads:
<au:AjaxFileUpload ID="Avatar" runat="server"
AllowedExtensions=".jpg,.png,.gif,.webp"
EnableImageDimensions="true"
MinImageWidth="200"
MinImageHeight="200"
MaxImageWidth="4000"
MaxImageHeight="4000"
ButtonText="Select Image"
AutoUpload="true"
ShowProgress="true" />
Choose the bounds for your use
The minimum protects image quality, and the maximum protects the server. A minimum that matches the largest display size avoids upscaling. A maximum that is a few times that size keeps resize jobs cheap. The values above, 200 by 200 to 4000 by 4000 pixels, are a starting point, not a rule.
Keep the server check
The browser reads dimensions from the file header. The server should still decode the image before it trusts it, and it should reject anything that fails to decode. The image uploads guide covers confirming that a file really is an image, along with resizing and EXIF stripping.
Try it
The image dimensions demo runs the markup above. Pick an image that is too small, then one that fits.
Related