I have a photograph that I'm loading into my LaTeX document.
I'd like the photograph to have rounded corners and no visible border.
I'd prefer not to edit the original photograph.
Any thoughts on how to do this?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI have a photograph that I'm loading into my LaTeX document.
I'd like the photograph to have rounded corners and no visible border.
I'd prefer not to edit the original photograph.
Any thoughts on how to do this?
Another possibility if you want to fix the dimensions of the pictures :
\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip [rounded corners=.5cm] (0,0) rectangle coordinate (centerpoint) (5,7.5cm);
\node [inner sep=0pt] at (centerpoint) {\includegraphics[width=6.0cm]{EiffelTall.jpg}};
\end{scope}
\begin{scope}[xshift=7cm]
\clip [rounded corners=.5cm] (0,0) rectangle coordinate (centerpoint) ++(5cm,7.5cm);
\node [inner sep=0pt] at (centerpoint) {\includegraphics[width=10.0cm]{EiffelTall.jpg}};
\end{scope}
\end{tikzpicture}
\end{document}
++
works or is needed in the second example? I am trying to gain a solid understanding by grasping your answer along with Paul Gaborit's answer here: tex.stackexchange.com/a/76216/13552 These methods are much better than "the white box" methods because they don't require a white background.
Feb 3, 2016 at 13:42
One way would be to use tikz
to create a node with the image, and draw a rectangle with rounded corners using white color to clip the image. Here is the original image and one with the white rectangle drawn over it:
\ClipSep
defined the amount of clipping so this can be adjusted as desired.\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\newcommand*{\ClipSep}{0.4cm}%
\begin{document}
\includegraphics[width=5.0cm]{images/EiffelTall.jpg}
%
\begin{tikzpicture}
\node [inner sep=0pt] at (0,0) {\includegraphics[width=5.0cm]{images/EiffelTall.jpg}};
\draw [white, rounded corners=\ClipSep, line width=\ClipSep]
(current bounding box.north west) --
(current bounding box.north east) --
(current bounding box.south east) --
(current bounding box.south west) -- cycle
;
\end{tikzpicture}
\end{document}
\noindent
before the \begin{tikzpicture}
, and use \includegraphics[width=\linewidth,keepaspectratio]
. If that does not solve your issue, I would suggest you post a new question with a MWE including \documentclass
and the appropriate packages that sets up the problem.
Nov 21, 2014 at 21:47
\includegraphics[width=\myfactor*\linewidth,keepaspectratio]
notice myfactor correction. Should I post a new question?
I borrowed an image from Herbert's answer without his permission.
User defined data:
\def\M{3}% columns
\def\N{3}% rows
\def\scale{1}% scale
\def\filename{herbert}% filename
% Specify the cropping area.
\def\L{-2}
\def\B{-1.5}
\def\R{2}
\def\T{3}
Steps:
xelatex
or latex-dvips-ps2pdf
. See the result, if the cropping region does not suit your requirement, do the 3rd and 4th again.Hopefully, the given comments in the code are self-explanatory.
\documentclass[pstricks,border=12pt]{standalone}
\def\M{3}% columns
\def\N{3}% rows
\def\scale{1}% scale
\def\filename{herbert}% filename
\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=\scale]{\filename}}
\usepackage{pstricks}
\psset
{
xunit=0.5\dimexpr\wd\IBox/\M\relax,
yunit=0.5\dimexpr\ht\IBox/\N\relax,
}
\begin{document}
% The following figure shows an image with a grid enabled.
% Use the grid to find the cropping area.
\begin{pspicture}[showgrid=true](-\M,-\N)(\M,\N)
\rput(0,0){\usebox\IBox}
\end{pspicture}
% Specify the cropping area.
\def\L{-2}
\def\B{-1.5}
\def\R{2}
\def\T{3}
\begin{pspicture}[showgrid=false](\L,\B)(\R,\T)
\begin{psclip}{\psframe[linestyle=none,framearc=0.5,dimen=middle](\L,\B)(\R,\T)}
\rput(0,0){\usebox\IBox}
\end{psclip}
\end{pspicture}
\end{document}
Original image with a grid.
Cropped image.
I'm surprised that nobody presented the solution of tikz, but when you don't know the size of the node. The idea is to print it one using phantom
to get the size, and then use the tikz clip function.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{graphicx}
\newcommand*{\bord}{1mm}
\begin{document}
\begin{tikzpicture}
\def\ig{%
\includegraphics[width=7cm,height=7cm,keepaspectratio]{example-image-10x16}}
\node [inner sep=0pt](mypicture) at (0,0) {\phantom{\ig}};
\clip[rounded corners=5mm] ($(mypicture.south west)+(\bord,\bord)$) rectangle ($(mypicture.north east)-(\bord,\bord)$);
\node[inner sep=0pt](mypicture) at (0,0) {\ig};
\end{tikzpicture}
\end{document}
file:///tmp/Spectacle.f17590.png
\draw[gray, rounded corners=5mm, line width=2pt] ($(mypicture.south west)+(\bord,\bord)$) rectangle ($(mypicture.north east)-(\bord,\bord)$);
right before \end{tikzpicture}
\bord
? I'm using this solution without it.
Jun 15 at 19:02
\bord
is just a shortcut for 1mm
that I defined above: \newcommand*{\bord}{1mm}
. I use it to avoid changing 1mm
in multiple places (another option is to write directly a macro for that)
Jun 16 at 11:34
If you just want round corners there are an easy solution: just use GIMP. Take your picture, go on filter -> decoration -> round corners and there you can make round corners and put a shadow beneath and a lot more.
I know it is not a really "LaTeX-solution", but it is the most easy thing to do. If you need to use Tikz everytime you will make round corners, it would take a lot of time. Especially if you use other commands on the picture already (minipage and so on). You can save a lot of time with using such simple methods as GIMP - so you can use it on more LaTeXic things.