Simulating CSS 'background-size: cover' effect on HTMLImageElement (<img>) with optional horizontal and vertical alignments.