5

I have the following image

enter image description here

Is there some way for me in Tikz, to remove the part to the right of the white line, and insert it with a slide of another image? Ideally I should be able to select 0-1 how far the image is to the right.

For instance with the following image,

enter image description here

the result could look like this

enter image description here

Sorry for no MWE, as I am very unsure where to start. Any help getting started would be much appreciated.

EDIT:

Thanks to Ignasis I was able to produce an MWE. The result looks like this

enter image description here

Improvements / Things I was not able to fix myself

  • I was not able to include my original 8pyV9.jpg as this kept throwing me an Package graphics Error: Division by 0.?. Why? I tried to change the filename, alas nothing helped.

  • Why is there a white margin on the bottom and to the right of the images? I would like them to be flush with the page borders.

  • Is there a way to make sure the blue image fits the pagewidth, where the white line is correctly placed? I was able to set it correctly manually now, but if I change the page borders, it throws everything off.

  • Is it possible to move the right image right and left to choose which parts is included?

MWE

\documentclass{article}
\usepackage{tikz}

\usepackage[b5paper,lmargin=25mm, rmargin=25mm,tmargin=27mm, bmargin=30mm]{geometry}

\usepackage{graphics,graphicx,calc}
 \definecolor{main}{HTML}{003349}

\begin{document}

\pagestyle{empty}

\newgeometry{margin=0pt}

\def\mygraphic{\includegraphics[width=\textwidth]{Q7xB7.png}}
\newlength\graphicheight
\setlength\graphicheight{\heightof{\mygraphic}}

\vspace*{\fill}\noindent%
\begin{tikzpicture}
    %
    \begin{scope}
        \path[clip] (18,0)--++(180:6.7cm)--++(70:\graphicheight)-|cycle;
        \node[anchor=south east] at (18,0) {\includegraphics[height=\graphicheight]{uniwallpaper.jpeg}};
        % \fill[color=main,opacity=0.8] (0,0) rectangle (\textwidth,\graphicheight);
    \end{scope}
    \begin{scope}
        \path[clip] (0,0)--++(0:11.2cm)--++(70:\graphicheight)-|cycle;
        \node[anchor=south west] {\includegraphics[width=\textwidth]{Q7xB7.png}};
    \end{scope}
\end{tikzpicture}

\end{document}
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114

3 Answers3

6

To expand on Ulrike's comment, here is a quick and dirty example on how to clip an external image that is directly taken from the pgf manual

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx,tikz}
\begin{document}
\begin{tikzpicture}[path image/.style={
path picture={
\node at (path picture bounding box.center) {
\includegraphics[height=3cm]{#1}
};}}]
\draw [path image=example-image-b,thick](0,1) -- (0,3) -- (1.5, 1.5) -- (1,1) -- cycle;
\end{tikzpicture}
\end{document}

Then you can superimpose two images, once having clipped one.

enter image description here

Denis
  • 5,267
6

Another solution clipping images included as nodes:

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\path[clip] (0,0)--++(0:3.5cm)--++(75:3cm)-|cycle;
\node[anchor=south west] {\includegraphics[width=6cm]{Q7xB7}};
\end{scope}
\begin{scope}
\path[clip] (6,0)--++(180:2.3cm)--++(75:3cm)-|cycle;
\node[anchor=south east] at (6,0) {\includegraphics[height=3cm]{8pyV9}};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Update

If you want to cover some part of the page with this picture, it's better to use absolut positioning, which can be done with remember picture and overlay options and using the current page node. You need to compile twice before getting the correct result.

The white space around the figure was due to inner sep which keeps a certain distance between node contents and border. With inner sep=0pt, there is no space.

Finally you can use bb ("bounding box") option from graphicx package to select which part of the included figure is shown: bb=0 0 1400 702 means take the rectangle from (0,0) to (1400,702) points (Postscript points not pixels). I think you'll have to test to find the desired fragment.

\documentclass{article}
\usepackage{tikz}
\usepackage[b5paper, lmargin=25mm, rmargin=25mm, tmargin=27mm, bmargin=30mm]{geometry}

%\usepackage{graphics,graphicx,calc}
\usepackage{calc}
\definecolor{main}{HTML}{003349}
\pagestyle{empty}

\def\mygraphic{\includegraphics[width=\paperwidth]{Q7xB7.png}}
\newlength\graphicheight
\setlength\graphicheight{\heightof{\mygraphic}}

\begin{document}

\begin{tikzpicture}[overlay, remember picture]
    %
    \begin{scope}
        \path[clip] (current page.south west)--++(0:10.8cm)--++(70:\graphicheight)-|cycle;
        \node[anchor=south west, inner sep=0pt] at (current page.south west) {\mygraphic};
    \end{scope}%
    \begin{scope}
        \path[clip] (current page.south east)--++(180:6.7cm)--++(70:\graphicheight)-|cycle;
        \node[anchor=south east, inner sep=0pt] at (current page.south east) {\includegraphics[height=\graphicheight, bb=0 0 1400 702, clip]{8pyV9}};
    \end{scope}
\end{tikzpicture}

\end{document}

enter image description here

Ignasi
  • 136,588
  • This seems close, but it still seems I have to manually set the dimensions. What I really want is the deep blue to fill the bottom of the page, and then stretch or shrink the other half to fit the space. Here is what I have so far https://i.imgur.com/3OqC3HJ.png. I can add an MWE in the first post or create a new question. – N3buchadnezzar Oct 01 '19 at 12:06
  • @N3buchadnezzar Please, take a look at updated answer. I hope it's better now. – Ignasi Oct 01 '19 at 14:08
4

This is very similar to the other two answers with the main difference being that I install a local coordinate system on the pic to make things more convenient. You still need to find out the coordinates by looking, but now the clip path becomes

\clip (0.6345,0) -- (0.963,1) -| (1,0) -- cycle;

where the coordinates are such that (0,0) is the lower left and (1,1) the upper right corner of the "reference" picture. This way you do not have to put in explicit dimensions.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[b5paper,lmargin=25mm, rmargin=25mm,tmargin=27mm, bmargin=30mm]{geometry}
\begin{document}
\begin{tikzpicture}[nodes={inner sep=0pt,anchor=south west}]
 \node (X) {\includegraphics[width=\textwidth]{picA}};
 \begin{scope}[x={(X.south east)},y={(X.north west)}]
  \begin{scope}
   \clip (0.6345,0) -- (0.963,1) -| (1,0) -- cycle;
   \path let \p1=(X.north east) in (0,0) 
   node{\includegraphics[width=\x1,height=\y1]{picB}};
  \end{scope}
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • @Schödinger's cat This seems very close! Is there a way to move the triangle image more to the right? – N3buchadnezzar Oct 01 '19 at 17:26
  • @N3buchadnezzar The position of the triangle is specified in \clip (0.6345,0) -- (0.963,1) -| (1,0) -- cycle;, which says that the lower left point is at 63.45% of the width and the upper point at 96.3% of the width. If you increase these x coordinates, the triangle will move right. (I adjusted these values to match the white line in your image.) –  Oct 01 '19 at 17:30
  • English is hard! The placement of the white line is perfect. I wonder if it is possible to move the underlying image like so https://i.stack.imgur.com/PSTfh.png – N3buchadnezzar Oct 01 '19 at 17:38
  • @N3buchadnezzar Sure. Just replace \path let \p1=(X.north east) in (0,0) node{\includegraphics[width=\x1,height=\y1]{picB}}; by \path let \p1=(X.north east) in (0.1,0) node{\includegraphics[width=\x1,height=\y1]{picB}};, i.e. increase the x position of the second picture. (I am on a different machine now, so I can't tell if 0.1 is a good choice, but you need to increase the x value of the coordinate.) –  Oct 01 '19 at 17:47
  • Yes, yes. I was able to figure this out right after asking. I can adjust the values myself. I am creating a package where the user is given the options to add images and move them. My images are just for examples =) – N3buchadnezzar Oct 01 '19 at 18:00