Simulating CSS 'background-size: cover' effect on HTMLImageElement with optional horizontal and vertical alignments.