Currently, I am working on a drawing app and have come across an issue that has been challenging for me to resolve. The dilemma lies in resizing the canvas of sketches from the original resolution of 1280 x 720 to the maximum size possible upon opening the page. This resizing should maintain the 1280 x 720 aspect ratio, while also accounting for a toolbar located at the top of the page.
The goal is to center the canvas on the screen, with black stripes filling the remaining space based on the dimensions of the browser window. If the window's aspect ratio is less than that of the sketch, horizontal black stripes will be displayed (see fig 1). Conversely, if the aspect ratio is greater, vertical black stripes will be shown (refer to fig 2).
To tackle this challenge, I experimented with JavaScript by calculating the offsetWidth and offsetHeight of a div containing a programmatically generated invisible image matching the original sketch dimensions. However, relying solely on these properties proved to be unreliable as they were not consistently ready when the page loaded, necessitating the use of timers or mutation observers.
I have dedicated significant time to finding a robust solution to this problem, but each approach I discovered seemed either too hacky or prone to errors. Any assistance or suggestions would be greatly appreciated as I work within the Angular + Ionic 4 framework.