The invert() function is an inbuilt function that is used to apply a filter to the image to set the invert of the color of the sample image.
invert( amount )
Parameters: This function accepts single parameter amount which holds the amount of conversion. The value of invert is set in terms of value and percentage. The value 0% represents original image and 100% represents the inverted image.
The invert() function internally uses the following formula, to computer the inverse of the image:
amount * (255 - value) + (1 - amount) * value
The value of inversion is controlled by the variable
amount, the variable value lies between 0 – 1(floating) range (this is done by converting the passed percentage of color inversion to a value between 0-1). The value is the the color value of the pixel.
(255-value) gives the color after subtracting the color value with the max pixel value, assumes that the value of the pixel is in the range 0 – 255 (though input image sample space could be stretched/scaled to meet the specified criteria).
Below is a table containing a list of inversion percentages and the result they produce.
|50%||Image with each pixel having grey color|
|100%||Completely inverted Image|
Below example illustrates CSS invert() function in CSS:
Supported Browsers: The browsers supported by invert() function are listed below:
- Google Chrome
- Internet Explorer
- D3.js | d3.continuous.invert() Function
- Underscore.js | _.invert() Function
- Node Jimp | invert
- How to get the function name inside a function in PHP ?
- D3.js now() function
- PHP | ord() Function
- PHP | end() Function
- CSS env() Function
- PHP | Ds\Map xor() Function
- p5.js | value() Function
- PHP | Ds\Set xor() Function
- D3.js zip() Function
- CSS | url() Function
- PHP | Ds\Map put() Function
- PHP | exp() Function
- PHP | dir() Function
- D3.js | d3.max() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : deosurya2019