1

I am pretty new to tikz. I would like to use a simple external image inside a tikzpicture environment, like in the following mwe

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[double = black!35,double distance =0.2cm,line width =0.08cm,white] 
 (-4,0) -- (-0.5,0) arc (-90:0:2.5 and 2) arc (0:180:2) ;
\draw[double = black!35,double distance =0.2cm,line width =0.08cm,white] 
 (4,0) -- (0.5,0) arc (-90:-190:2.5 and 2);
\node [xscale=1,shift={(3,0.5)}] at (0,0) {\includegraphics[width=1cm]{motorbike.png}};
\end{tikzpicture}
\end{document}

where motorbike.png is this image

sorry, the small version is cropped for some reason...

The above code does what I need when compiled with pdflatex.

My problem is that I'd like to use the code in tikzjax which, from what I understand, runs on LaTeX and won't handle a raster format such as png.

Since the "external" image is a simple silhouette, I thought I could "easily" turn it into a tikz picture and use it inside my other tikzpicture.

After installing potrace and svg2tikz (as suggested e.g. here) I actually succeeded in creating a tikz code for "motorbike.png", but I'm having a really hard time inserting this code in my tikzpicture.

The output from svg2tikz is pretty long, and can be downloaded here.

This "standalone" code compiles correctly and produces a nice tracing of the original image.

I am having trouble using this output in my MWE, though. I initially thought of using the \path part only, but this produces a "dimensions too large" error, probably because of the "big" numbers in the path.

I tried experimenting with the scaling parameters of potrace and svg2tikz, but these had an effect only on tikz options such as "xscale" and "yscale", while the "big" numbers remained unaffected.

Next, I tried to work my way from the output of svg2tikz. That is, I tried inserting the other stuff from my MWE into it, as opposed to the other way round, which seems more "natural" to me. After some trial and error I came up with this code, where i put the path part of the svg2tikz output in a separate "path.tex" file for brevity.

\documentclass[tikz]{standalone}
\begin{document}
\def \globalscale {1.00000}
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=30, xscale=30, inner sep=0pt, outer sep=0pt]
\draw[double = black!35,double distance =4,line width =1,white] (-4,0) -- (-0.5,0) arc (-90:0:2.5 and 2) arc (0:180:2) ;
\draw[double = black!35,double distance =4,line width =1,white] (4,0) -- (0.5,0) arc (-90:-190:2.5 and 2);
\begin{scope}[shift={(2.5,0)},xscale=0.0002,yscale=0.0002,fill=black]
\input{path.tex}
\end{scope}
\end{tikzpicture}
\end{document}

The result is kind of ok, and does work in tikzjax. This can be verified in the tikzjax demo page, although for some reason the yscale must be inverted.

Now my question is the following: is there a more natural way of including a tikz figure in a pre-existing tikz "environment"?

The reason I am asking this is that in this case I created the "loop the loop" ramp and then thought "let's find a nice image of a motorbike".

It seems to me that the above solution requires to find a tikz image (path) first, and then drawing the "environment" around it, which seems a little unnatural.

Also, suppose I want to use different images (maybe a car, or a bicycle tries the "loop the loop"). I think that the risk is that the scales of different images would be likely different, and matching the scale of the "environment" to it could be tricky. It would be definitely easier to match the scale of the images to the environment, like in \includegraphics[width = 1cm]{image.png}.

Is there a way of doing this? I spent three days looking into it, and the best I accomplished is what I described above.

Thanks a lot for your help.

Francesco

PFB
  • 13

0 Answers0