Is there a way to achieve magnification like the one shown below using Spy library in TikZ? If so, how to achieve it? If not so, what better alternatives are there?
The thick yellow outlines below are not necessary. But I do want to achieve solid boundaries and dashed projection lines.
My MWE:
\documentclass[border=3mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}
\begin{scope}[spy using outlines={rectangle,magnification=4, size=2.5cm,connect spies}]
\node[rectangle,draw,inner sep=1pt] (image) at (0,0){\includegraphics[width=70px,height=70px]{image1.jpg}};
\spy on (0,0) in node at (0,4);
\end{scope}
\end{tikzpicture}
\end{document}
produces
UPDATE 1
I managed to get the dashed square projection in the following way:
\documentclass[border=3mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}
\begin{scope}[spy using outlines={thick,red,rectangle,magnification=4, size=2.5cm,connect spies}]
\node[rectangle,draw,inner sep=1pt] (image) at (0,0){\includegraphics[width=70px,height=70px]{image1.jpg}};
\spy[spy connection path={
\draw[densely dashed] (tikzspyinnode.north west) -- (tikzspyonnode.north west);
\draw[densely dashed] (tikzspyinnode.south west) -- (tikzspyonnode.south west);
\draw[densely dashed] (tikzspyinnode.north east) -- (tikzspyonnode.north east);
\draw[densely dashed] (tikzspyinnode.south east) -- (tikzspyonnode.south east);
}] on (0,0) in node at (1.5,3.5);
\end{scope}
\end{tikzpicture}
\end{document}
which produces
The only problem is that the dashed lines cross over the magnified image as you can see. How to send them behind?
UPDATE 2
If I use the on background layer
as scope option, it did solve for the magnifying part, but then again these lines go behind the actual image:
\documentclass[border=3mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{spy,backgrounds}
\begin{document}
\begin{tikzpicture}
\begin{scope}[spy using outlines={thick,red,rectangle,magnification=4, size=2.5cm,connect spies}]
\node[rectangle,draw,inner sep=1pt] (image) at (0,0){\includegraphics[width=70px,height=70px]{image1.jpg}};
\spy[fill=white,spy connection path={
\begin{scope}[on background layer]
\draw[densely dashed] (tikzspyinnode.north west) -- (tikzspyonnode.north west);
\draw[densely dashed] (tikzspyinnode.south west) -- (tikzspyonnode.south west);
\draw[densely dashed] (tikzspyinnode.north east) -- (tikzspyonnode.north east);
\draw[densely dashed] (tikzspyinnode.south east) -- (tikzspyonnode.south east);
\end{scope}
}] on (0,0) in node at (1.5,3.5);
\end{scope}
\end{tikzpicture}
\end{document}
\includegraphics[width=3cm]{example-grid-100x100pt}
(tex.stackexchange.com/questions/231738). This makes MWEs portable.