Assigning width and height to specify image dimension using jQuery
The reason GTMetrix complains is that the browser can render the page faster if it knows the size of the image. 

Setting the size after the browser has rendered is not going to make your page faster, it will only make the warning go away and fractionally make your page load slower.

This means you will have to declare the height and width of the image on the server side, or ignore the warning of GTMetrix.