Read image dimensions
See original GitHub issueHello, and thanks for the great lib!
Is there a way to access the image dimensions within Uppy without need to go through a Blob -> FileReader -> Image conversion? I was unable to find a width
/height
metadata fields on the objects returned by the upload-success
and complete
events.
I’m currently doing this like so:
// convert the blob URL to an object
let objFile = await fetch(elem.preview)
let objBlob = await objFile.blob()
// convert it to a data URI
let reader = new FileReader()
reader.readAsDataURL(objBlob)
reader.onload = e => {
// retrieve the image dimensions
let image = new Image()
image.src = e.target.result
image.onload = (loadEvent) => {
// all done
resolve({
thumbnail: e.target.result,
url: elem.uploadURL,
width: loadEvent.path[0].width,
height: loadEvent.path[0].height,
aspectRatio: loadEvent.path[0].width / loadEvent.path[0].height
})
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Image Size Finder | Free Tool - PosterBurner
Find the size and pixel depth of your image. This free tool shows you the height, width, and pixel per inch of your...
Read more >How to find image size & dimensions info on your computer
On a PC (Windows 10): Open Windows Explorer and find the image you want to check. The dimensions and file size appear in...
Read more >Determine an image's file size and dimensions
Click Finder on your Dock. Image of the Finder icon. · Find the image you want to check. · Control+click (ctrl+click) your image....
Read more >How to get image size (height & width) using JavaScript?
You can programmatically get the image and check the dimensions using Javascript... const img = new Image(); img.onload = function() { alert(this.width + ......
Read more >Get image size (width, height) with Python, OpenCV, Pillow (PIL)
This article describes how to get the image size (width, height) in Python with OpenCV and Pillow (PIL).The image size can be obtained...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Indeed uppy doesn’t have these built in. It would be possible to do with a plugin.
For the Blob/FileReader dance, the easier thing to do is to use URL.createObjectURL, which saves a few steps:
As for the
.preview
property, it’s already a blob URL, which can be assigned directly to an Image’s.src
:Then you do not need the URL.createObjectURL and URL.revokeObjectURL calls.
Related: It would be also nice to add the image dimensions as a restriction.