This doesn't require custom coding. You mainly need to set the different product images to the desired dimensions/proportions.
The "small" image (the base image you select in the product editing page) can be set in admin > Configuration > Images to a horizontal layout with width 300px and height 30px or whatever.
The "medium" image (which shows on the product info page) can be set to width 50px and height 500px, and the "large" image can be set as desired for a vertical or horizontal layout.
Each of those sizes is a separate image file which can be oriented as you wish. The image files should each be made the exact size and orientation you want to display them at. The medium and small images should not be the same 58k as the large image. Small image files load much faster; the "small" image should be something like 5k.
See the tutorials for instructions on using different image sizes.



