# Inset within Image [duplicate]

Can anyone who is well versed in tikz draw help me to include a small inset inside a larger image? (The inset - image 2 - is a "zoomed in" of the smaller inset in image 1 ).

I couldn't do that in tikz, then I tried to do this manually using gimp software (see image below) and lost image quality in the inset (I had to scale the image 2 within a frame I drew and connected two ends (right-north and left-south) to a small inset in image 1. Unfortunately the smaller inset (where the green contours are embedded) in image 1 is not visible because of the color black I used to draw the lines.

Thank you very much!

• does this help: Image inside another image Sep 15 '15 at 19:23
• Thanks for the link. It solves half of the problem. Any idea how can I include the lines connecting the ends of the bigger (image 2) and smaller (in the middle of image 1 - unfortunately it is invisible due to black colour I used ) insets?
– A_V
Sep 15 '15 at 19:53

You can spy on the particular region:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,spy}

\begin{document}
\begin{tikzpicture}
\begin{scope}[
node distance = 11mm,
inner sep = 0pt,spy using outlines={rectangle, red, magnification=6,
%connect spies
}
]
\node (n0)  {\includegraphics[width=\textwidth]{example-image-a}};

\spy [blue,size=3cm] on (n0.center) in node[below right=of n0.north west];
\end{scope}
\draw[dashed,blue] (tikzspyonnode.north east) -- (tikzspyinnode.north east);
\draw[dashed,blue] (tikzspyonnode.south west) -- (tikzspyinnode.south west);
\end{tikzpicture}
\end{document}


Adjust the size=3cm and magnification=6 values appropriately.

When you insert graphics into nodes, then drawing connection between them is easy:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{graphicx}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 11mm,
inner sep = 0pt
]
\node (n0)  {\includegraphics[width=\textwidth]{example-image}};
\node[at=(n0.center)]    (n1)
{\includegraphics[width=0.1\textwidth]{example-image-a}};
\node[below right=of n0.north west] (n2)
{\includegraphics[width=0.3\textwidth]{example-image-b}};
\draw[densely dashed]   (n2.north east) -- (n1.north east)
(n2.south west) -- (n1.south west);
\end{tikzpicture}
\caption{Galaxy}
\end{figure}
\end{document}


You just connect by lines between anchors of nodes: