沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

"JavaScript" Common Image Ratio Generation

I tried several online tools for calculating ratios, but none of them worked well... So I wrote some JS code to iterate through them... You can also modify the parameters for other sizes... I guess...

(() => {
  const iList = [
    [16, 9],
    [5, 4],
    [5, 3],
    [4, 3],
    [3, 2],
    [3, 1],
    [2, 1],
  ];
  const wList = [640, 960, 1024, 1280, 1366, 1440];
  let strRlt = "";
  iList.forEach((i) => {
    strRlt += "__" + i.join("__x__");
    strRlt += `\n(Width / Height) = ` + i[0] / i[1];
    strRlt += "\n";
    wList.forEach((w) => {
      h = (w / i[0]) * i[1];
      if (h == parseInt(h)) {
        strRlt += `${w} x ${h}`;
        strRlt += "\n";
      }
    });
    strRlt += "\n";
  });
  console.log(strRlt);
})();

Execution result:

__16__x__9
(Width / Height) = 1.7777777777777777
640 x 360
960 x 540
1024 x 576
1280 x 720
1440 x 810

__5__x__4
(Width / Height) = 1.25
640 x 512
960 x 768
1280 x 1024
1440 x 1152

__5__x__3
(Width / Height) = 1.6666666666666667
640 x 384
960 x 576
1280 x 768
1440 x 864

__4__x__3
(Width / Height) = 1.3333333333333333
640 x 480
960 x 720
1024 x 768
1280 x 960
1440 x 1080

__3__x__2
(Width / Height) = 1.5
960 x 640
1440 x 960

__3__x__1
(Width / Height) = 3
960 x 320
1440 x 480

__2__x__1
(Width / Height) = 2
640 x 320
960 x 480
1024 x 512
1280 x 640
1366 x 683
1440 x 720
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.