Keeping image ratio's

by 3 replies
4
#programming #image #keeping #ratio
  • It's actually pretty simple.

    Take your desired width (300 pixels) and divide by the current width (eg. 900 pixels).

    Then take that result and multiply it by your height to achieve the same ratio.

    So for example:

    You have an image 600 (width) X 780 (height) and you want the new image to have a with of 300.

    So..

    300 / 600 = 0.5
    0.5 * 780 = 390 (new height)

    Hope that helps!
    • [1] reply
    • Thats correct. But why do you need it?
  • Banned
    [DELETED]
  • In HTML, if you just specify the width in the image tag, it will scale it proportionally. For example: <img src="image.png" width="300" />

Next Topics on Trending Feed