TeX - LaTeX Asked on December 15, 2020
I have an image like this texture background reproduced here that I would like to display varying from dark-blue to white on the two opposite corners, as if it were being viewed by a colored lens.
I tried a few things like:
documentclass{report}
usepackage{tikz}
begin{document}
begin{tikzpicture}
node[opacity=0.4,fill=blue] at (0, 0) {includegraphics[scale=0.5]{DvhfC.jpg}};
end{tikzpicture}
end{document}
but the variation does not quite work down to white and it also leaves a blue frame around the entire picture, as in:
Is there a transformation that can accomplish that in TikZ?
The approach used in the OP adds opacity to two separate objects (JPEG image, node background fill) and subsequently overlays them. But, adding opacity removes contrast from the original JPEG, blurring the texture it provides. As a result, one only gets a somewhat pale composite picture.
The canonical way, however, is to define a transparency mask (fading) from the JPEG image that can later be used to mask other graphical objects. Like shadings, pgf/TikZ fadings are scaled before being used (see PGF manual, section 114.3). Therefore, in order to use the full JPEG image when applied as a mask, we scale it to 50bp x 50bp size with a 25bp margin added upon mask creation.
documentclass{report}
usepackage{tikz}
usetikzlibrary{fadings}
begin{document}
begin{tikzfadingfrompicture}[name=mask image]
node [inner sep=25bp] {includegraphics[width=50bp,height=50bp]{DvhfC}};
end{tikzfadingfrompicture}%
% Now we use the mask in another picture:
begin{tikzpicture}
fill [blue,path fading=mask image] (0,0) rectangle (1,1);
fill [red,path fading=mask image] (1,1) rectangle (4,4);
fill [green,path fading=mask image] (2,0) circle [radius=1cm];
end{tikzpicture}
end{document}
Note that brighter areas of the mask image add less, while darker areas add more transparency to the object being masked:
Correct answer by AlexG on December 15, 2020
You can put your image and then shade
something over it (TikZ manual 15.7, "shading a path").
documentclass{report}
usepackage{tikz}
begin{document}
begin{tikzpicture}
node[opacity=0.5, inner sep=0pt](A) at (0, 0) {includegraphics[scale=0.5]{DvhfC.jpg}};
shade [left color=blue, right color=white, shading angle=135, opacity=0.5]
(A.south west) rectangle (A.north east);
end{tikzpicture}
end{document}
Be aware that this kind of transparency tricks can trigger PDF viewer "features" sometimes, so check if it works correctly for you (the grab is from okular
).
Answered by Rmano on December 15, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP