I'm reading the docs of PIL, Link, and I found this line
mask = source[R].point(lambda i: i < 100 and 255)
So what does it mean that i < 100 and 255?
This is featured in the paragraph right after:
Python only evaluates the portion of a logical expression as is necessary to determine the outcome, and returns the last value examined as the result of the expression. So if the expression above is false (0), Python does not look at the second operand, and thus returns 0. Otherwise, it returns 255.
If i < 100 is True, it returns 255. This makes sense considering the whole RGB colour scheme where RGB(255, 0, 0) returns Red.
But yes, this is bad practise. It should be:
mask = source[R].point(lambda i: 255 if i < 100 else 0)
Much more readable...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With