JavaScript code to resize an image to square dimensions