Redactions are filled rectangles that are drawn onto source images in order to highlight or obscure parts of them. This can be used for search result highlighting, copyright protection, or privacy protection, without altering any source images. Different redactions can be applied to the same image dynamically for different audiences based on client IP address, cookies, and more.
Redactions are defined with x
, y
, width
, and height
properties corresponding to source image coordinates, and a color
property defining the fill color and opacity. Redacted regions appear at every intersecting crop region and scale.
It can be tedious to obtain the coordinates of redaction rectangles manually. Instead, they are usually obtained from the output of various OCR tools.
The redaction feature works via the delegate system. The delegate must implement a method called redactions()
that returns an array of source image redaction coordinates in response to a particular request.
class CustomDelegate
def redactions(options = {})
redactions = []
# Add two redactions to an image with an identifier of "sample" for all
# clients except localhost.
if context['identifier'] == 'sample'
&& !%w(127.0.0.1 ::1/128).include?(context['client_ip'])
redactions << {
'x' => 50,
'y' => 65,
'width' => 120,
'height' => 105,
'color' => "rgb(151, 198, 222, 0.5)"
}
redactions << {
'x' => 673,
'y' => 812,
'width' => 1320,
'height' => 620,
'color' => "#97c6dea0"
}
end
redactions
end
end