meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.55k stars 404 forks source link

Problem when applying contrast #138

Closed semprom closed 10 years ago

semprom commented 10 years ago

Why when I do this this.contrast(50); it works and when I do this contr = '80'; this.contrast(contr); it doesn't work? When contr is '80' it doesn't work. When its 80 it works.

Very strange ...

Thanks.

meltingice commented 10 years ago

'80' is a string, while 50 is a number. Internally, the contrast method is doing:

('80' + 100) / 100

which does string concatenation first, and then converts to an integer when division is attempted. If you don't have control over your input data, run parseInt() on it before passing it to CamanJS.