Replies: 1 comment
-
Mask is basically an alpha-channel. Black parts are transparent, white parts are fully opaque, and grey parts are semi-transparent. Here's an example: Prawn::Document.generate('mask.pdf', page_layout: :landscape) do
# Drawn the background image spanning the whole page
canvas do
image "mountains.jpg", height: bounds.height
end
soft_mask do
canvas do
# White, we want these parts to be drawn
fill_color 'ffffff'
fill_rectangle([100, bounds.top - 100], bounds.width - 200, bounds.height - 200)
# Black, we want these parts to be transparent
fill_color '000000'
font 'Times-Roman', size: 144, style: [:bold] do
text_box "MASK",
align: :center, valign: :center,
at: [100, bounds.top - 100],
width: bounds.width - 200, height: bounds.height - 200
end
end
end
# The mask is applied to everything that follows.
# We just draw a full-page black rectangle. Notice how the parts outside the
# mask are not drawn.
canvas do
fill_color '000000'
fill_rectangle([0, bounds.top], bounds.width, bounds.height)
end
end The result: mask.pdf |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Can not figure out how to mask a rectangle with a text like on example image.
Rectangle should have transparent area defined by the text.
It feels like i need to combine fill_rule with soft_mask, but i can not find the right way to.
Beta Was this translation helpful? Give feedback.
All reactions