cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
819 stars 35 forks source link

Draw on top of images #539

Closed kescobo closed 5 months ago

kescobo commented 5 months ago

For constructing slides especially, it would be very useful to be able to place an image (eg using #image("path/to/thing.png") and then place drawings on top of it.

Something like this is possible with tikz, eg:

\begin{tikzpicture}
        \node[inner sep=0pt,anchor=south west] (img1) at (0,0)
            {\includegraphics[width=0.7\textwidth]{hsiao_5a.png}};
        \filldraw[white,very thick,anchor=south west] (2.6,0) rectangle (9.6,4.7);
        % \draw[step=0.2,anchor=south west,gray,thin] (0,0) grid (9.6,7); % to figure out coordinates
        % \draw[step=1.0,anchor=south west] (0,0) grid (9.4,6);
\end{tikzpicture}

I tried naively to add a call to image() inside a cetz figure,

  #cetz.canvas({
    import cetz.draw: *
    // Your drawing code goes here
    image("assets/decision-tree_1.png")
    // Draw a circle and place its "west" anchor at the origin.
    circle((0,0), anchor: "west")
  }) 

But this gives

error: cannot join content with array

Is there any way to accomplish this?

johannes-wolf commented 5 months ago

Wrap your image call in a content(...) call. CeTZ' content is a function to display native Typst content inside a CeTZ canvas.