DEV Community

MICHAEL-MAURICE
MICHAEL-MAURICE

Posted on

1

Resize Images in asp.Net

I was doing a task today, and part of it was that I was uploading images..but there was a problem that would happen if the user uploaded a large image. I want to control the size of the image that I came from the user because my database is arrogant. this ..
The first thing I need to do is check the size of the image before I do it and save it. This is how I compare the length of the image (array of bytes) with the length I need, even if it is larger than it. Do not allow the user to upload this image.
The second thing is that I resize the image that I came to before I save it, and I found two packages that do this
1- SixLabors.ImageSharp, and you can read more about it here: https://www.nuget.org/packages/SixLabors.ImageSharp/2.0.0?_src=template
2- System.Drawing.Common, and you can read more about it here:-
https://www.nuget.org/packages/System.Drawing.Common/6.0.0?_src=template
And they are both, through which you can specify the width and height of your image, and this is how you can let the user upload any image, regardless of its size....

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs