GeneralShaping an Image

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
JLeon
Posts: 2
Joined: Sun Dec 09, 2007 10:21 pm

Shaping an Image

Post by JLeon »

Hi !

I new to Latex and I want to know if there is a way to cropping pictures into non-rectangular shapes in Latex

Tks...

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Shaping an Image

Post by localghost »

As far as I know that is not possible. You have to provide the general shape of the pictures by yourself. There may be a workaround with the clipping technology provided by pgf/tikz or pstricks, where pstricks only works directly with latex and indirectly with pdflatex when supported by pst-pdf.


Best regards an welcome on Board
Thorsten
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Shaping an Image

Post by Juanjo »

As pointed out by localghost, there is a workaround with pgf/tikz. Try the following example:

Code: Select all

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
 \centering
 \includegraphics{ctanlion.jpg}
 \caption{The whole \TeX\ lion.}
\end{figure}

\begin{figure}
  \centering
  \begin{tikzpicture}
    \clip (0,0) circle (4cm);
    \pgftext{\includegraphics{ctanlion.jpg}};
  \end{tikzpicture}
  \caption{The \TeX\ lion cropped by a circle.}
\end{figure}

\begin{figure}
  \centering
  \begin{tikzpicture}
    \clip (0,4) ..controls +(120:2cm)
        and +(90:2cm) .. (-4,3) .. controls  +(-90:2cm) and +(90:3cm) ..
        (0,-5) .. controls +(90:3cm) and +(-90:2cm) ..(4,3)  .. controls
        +(90:2cm) and  +(60:2cm) .. (0,4);
    \pgftext{\includegraphics{ctanlion.jpg}};
  \end{tikzpicture}
  \caption{The \TeX\ lion cropped by a heart.}
\end{figure}

\end{document}
I attach below the file ctanlion.jpg, so you can compile the above code with pdfLaTeX.

Edited: The lion's image can be obtained at different formats and resolutions from http://www.ctan.org/lion.html
The path for the cropping heart has been borrowed (and slightly modified) from http://www.fauskes.net/pgftikzexamples/valentine-heart/
Attachments
ctanlion.jpg
ctanlion.jpg (37.3 KiB) Viewed 4781 times
JLeon
Posts: 2
Joined: Sun Dec 09, 2007 10:21 pm

Re: Shaping an Image

Post by JLeon »

Thanks Juanjo. It worked perfectly
Post Reply