johndatserakis / file-upload-with-preview

🖼 Simple file-upload utility that shows a preview of the uploaded image. Written in TypeScript. No dependencies. Works well with or without a framework.

Home Page:https://johndatserakis.github.io/file-upload-with-preview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to check image dimensions(width and height) before preview and upload

codetestmg opened this issue · comments

Thanks for the library.easy to integrate.

Hi there! Thanks for checking out the project.

To check the image dimensions before upload, you could create a function that handles the evaluation and is run each time a file is uploaded.

To run a function each time files are uploaded, you could hook into the fileUploadWithPreview:imagesAdded window.addEventListener in your code.

To show you an example of how to get the width and height of the images that have been uploaded, I have set up a small example, but in this case, some code is run each time the Print Image's Width And Height To Console is clicked in the bottom left. Click the button after you have added a few images and then open your console. You'll see the images widths and heights displayed there. You can check out the code in the JavaScript section of the codepen to see how I inspected the image array.

This should get you going in the right direction. Let me know if I can help further, thank you.

Let me know if this ends up working for you - closing for now.