for the filtertype parameter value IMG_FILTER_CONTRAST what number values can it range from.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Even though the documentation states -255 to +255, it's not! It's supposed to be -100 to +100. But, there's a deeper issue:
PHP doesn't limit the number to 100. It's passed straight through to the underlying lib-gd with whatever number you specify. lib-gd also doesn't limit the range to 100, so whatever number you use has a direct effect on the pixels.
In lib-gd, the following formula is used to calculate the contrast:
You can see this for yourself here: https://bitbucket.org/libgd/gd-libgd/src/cdea9eb0ad01/src/gd_filter.c
This formula is supposed to turn the contrast you've requested in PHP (between 0 and 100) into a number between 0 and 1.
Problem is, because the range is never getting checked, it has a mathmatically weird effect on numbers outside the range.
If you enter 90 in PHP, lib-GD translates that to 0.9, and applies a contrast algorithm using that number. Makes sense. HOWEVER, if you enter 2000, lib-gd is now using -19 in its contrast algorithm, which is wildly different.
Firstly, you'll note any value above 100 or below -100 has the same effect of increasing the contrast, because of the maths.
To achieve an 'absolute' contrast effect, i.e. moving all pixels in the picture to either 0 or 255, 25600 is the number you want. A pixel with a value of 127 will become 0, and a pixel with a value of 128 will become 255.
This can be useful if you want to make an image completely flat colour (especially if you apply a greyscale filter first, you'll get full black and white).
I wouldn't rely on this behaviour though, because either PHP or lib-gd could start limiting the range in new releases.
So, in effect:
IMG_FILTER_CONTRAST
is -25600 to +25600Between -255 and 255
Source