4

I want to use a picture from the internet or from my computer to fill in the cube area. I need it to have a wooden texture. I've read something about tcolorbox and the tikz library, but it didn't help me any further.

This is the cube:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document} \begin{tikzpicture} \pgfmathsetmacro{\cubex}{2} \pgfmathsetmacro{\cubey}{1} \pgfmathsetmacro{\cubez}{1} \draw[fill=brown] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle; \draw[fill=brown] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle; \draw[fill=brown] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle; \end{tikzpicture} \end{document}

The image would be: https://img.myloview.de/sticker/plywood-texture-with-gnarl-and-natural-wood-pattern-400-170218458.jpg

enter image description here

Black Mild
  • 17,569
brinde
  • 71

2 Answers2

5

You can use the fill.image library:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{fill.image}

\begin{document} \begin{tikzpicture} \pgfmathsetmacro{\cubex}{2} \pgfmathsetmacro{\cubey}{1} \pgfmathsetmacro{\cubez}{1} \draw[fill stretch image=Ikcfv.png] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle; \draw[fill stretch image=Ikcfv.png] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle; \draw[fill stretch image=Ikcfv.png] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle; \end{tikzpicture} \end{document}

enter image description here

1

Save the picture with some name (I used the name wood.jpg) in some folder and copy the path. Then try this code:

\documentclass{article}
\usepackage{tikz}

% paste the path to the picture e.g \graphicspath{ {C:/images/tikz} }

\begin{document} \begin{tikzpicture}[scale=2] \tikzset{ wood/.style={% draw=black!10, path picture={% \node at (path picture bounding box.center) { \includegraphics[width=0.4\linewidth]{wood.jpg}};}}} \pgfmathsetmacro{\cubex}{2} \pgfmathsetmacro{\cubey}{1} \pgfmathsetmacro{\cubez}{1} \fill[wood] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle; \fill[wood] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle; \fill[wood] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle; \draw (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle; \draw (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle; \draw (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle; \end{tikzpicture} \end{document}

output:

enter image description here

Display Name
  • 46,933
miltos
  • 2,605