In my html5-based mobile app I have an image uploader which has the very basic functionality like any other - an image thumbnail once the picture to be uploaded is selected. For resizing down to the thumbnail size for preview purpose, I've played around with 2 ways:
- Simply set width and height on img tag and let the browser do the resize
- Use canvas to explicitly resize the image down to my desired size.
And I need some help choosing which way to go. So from some of my different tests I've boiled them down to these observed pros and cons.
Speed
It takes more time to do the work in javascript when using canvas to resize than just setting the src for img tag. However, my observation is that once the image is resized with canvas the display is much faster than using the img tag.
For instance, it would take around 1 to 2 seconds for the image to be seen after I add the Image object to be shown. Whereas it takes almost no time for the image to be seen after the drawImage method finishes for canvas-based resize. This led me to think that the actual resize for img tag only happens when the image is added into view?
Eitherway, both img and canvas rounded up at about the same speed with distribution of time used in different areas.
Memory
I need somebody to tell me if this is true?
- In Img tag, the full-size info of the image is still being stored although it's resized on display.
- And of course, in canvas, the image has already been redrawn to a smaller size image, so only the smaller image info is taking up memory.
So using the Img tag takes more memory unnecessarily? (just for thumbnail display purpose)
Thumbnail Quality
This I actually don't really care because my thumbnail is rather small. But I bet they are going to be similar anyway with Img tag having more variation across browsers?