Reputation: 1473
Looking for answer for 2 weeks. I have a tool which allows to adjust images' contrast and brightness directly in the web browser and use CSS3 properties to show result. But I should also apply these modification to original JPG at the server-side and output it back to user.
How can I do it? I am using PHP+Imagemagick, but can not find a way to do this conversion. Please help me.
Upvotes: 1
Views: 1101
Reputation:
The CSS3 brightness
filter simply multiplies the color values by the given constant.[1][2] To achieve the same effect with Imagemagick, use -evaluate Multiply
[3]. Alternatively, -function Polynomial
[4] can be used for the same effect. Other features such as -level
[5][6] and -brightness-contrast
[7][8] are less appropriate, because they multiply the color by the inverse of the given constant.
The CSS property filter: brightness(80%)
corresponds to the Imagemagick option -evaluate Multiply .8
.
The CSS property filter: brightness(120%)
corresponds to the Imagemagick option -evaluate Multiply 1.2
.
Setting options for Imagemagick in PHP (or migrating from PHP to something better) is an exercise for the reader.
Upvotes: 1
Reputation: 1473
I found a great function of ImageMagick which allows us to do anything with brightness and contrast. It is "-level".
But it doesn't allow to apply CSS3 brightness and contrast values directly. Thus I made a great investigation and calculate special formula to transfer CSS brightness and contrast values to "black point" and "white point" parameters of "-level" option. Please check this page (sorry, russian language, but you can use google translate). Roll to the bottom of page if you don't want to read all these equations.
Upvotes: 1