Vuejs compression ten times optimized image upload, image quality lossless, ElementUI upload component

Above: the main interface, which can be used to browse and collect screenshots on the mobile phone, and the source code address is given later, because I wrote it a long time ago, and I am too lazy to re-run the explanation and analysis code, so people with front-end and back-end foundations are required to view and select a
insert image description here
74KB Click Upload to upload this
insert image description here
insert image description here
74KB picture, and check the size of the uploaded picture in the background, um. . . This is because the picture is already very small, so the compression cannot reach ten times. You can test uploading pictures with more than 1MB, and the effect is obvious.
Remember to configure the server upload size limit.
insert image description here
Preview view:
insert image description here

Research source code gitee address:

https://gitee.com/liu-daixin/image-compression-upload

This code needs to be read by a certain basic person to understand, let's explain the compression steps

When selecting a picture, compress it (this is the experience obtained after many tests, put it into the file array after compression, remove it from the file array when removing the picture, so there will be no more or less uploaded picture files etc.)
Convert the image to base64 encoding, perform compression algorithm redrawing, and then decode it into a file stream.

If you want to know more details, please leave a message and contact me. I can explain the code privately when I have time.

Guess you like

Origin blog.csdn.net/m0_57249797/article/details/124774818