I have some images with random dimension and the the question is how can I scale (resize) it to exactly 960×1280 for example in JavaScript, but keep image origin aspect ratio:
- If the image is bigger than the expected size, it is scaled down (keeping aspect ratio) and the empty areas are filled with transparent color.
- If the image is smaller than the expected size, it is not scaled but centered and the empty areas are filled with transparent color.
I had read some on this topic but still could not resolve the problem.
This is not working for me: How to resize images proportionally / keeping the aspect ratio?
UPDATED: Working solution here, many thank to @Mr. Polywhirl Update solution