I need to open an image and check that the width and height are even numbers. If they are not -1px.
How do I check to see if a number is odd?
291px would = 290px
333px would = 332px
121px would = 120px
I need to open an image and check that the width and height are even numbers. If they are not -1px.
How do I check to see if a number is odd?
291px would = 290px
333px would = 332px
121px would = 120px
3
Answers
You could divide the original length by two, round it down with
Math.floor()
and multiply the result with two to get the desired result.Untested, but you should be able to do this:
That tests if the least significant bit is one (i.e.
x
is odd) and decrements it if so.You can check using modulus!