fix for flickering when typing fast

When typing fast the image flickers. I found out that it's due to setting canvas width/height each time, even if it's not necessary. Fix for this is to set canvas dimensions only if its current size is different from the image data.