Search code examples
image-processinglateximagemagickbeamergimp

Resizing screenshots/screen captures for inclusion in Beamer


Sorry, this may or may not be a programming question directly, but I am trying to resize screenshots with Imagemagick and Gimp to include in a Beamer presentation, but it comes out even blurrier than the resizing done by LaTeX.

For instance, in Beamer I might have a command to rescale the image \includegraphics[width=.5\textwidth]{fig.png}. Using something like

\begin{frame}
\message{width = \the\textwidth}
\message{height = \the\textheight}
\end{frame}

I have gotten the \textwidth and \textheight parameters in points (345.69548, 261.92444). So I have a script (in Python) that sends a system call to Imagemagick:

'convert %s -resize %.6f@ resized_%s' % (f,a,f)

where a is calculated as \textwidth*\textheight*0.5**2 and f is the file name. When I then go back into my Beamer presentation and include the resized figure, \includegraphics{resized_fig.png}, the size looks approximately correct but it's super-blurry. I also tried resizing in Gimp (using the GUI) but no luck either... help? Thanks...


Solution

  • If you want to preserve pixel sharpness, i.e. do not scale and interpolate pixels, but represent them as small squares, I suggest this approach:

    1. Convert you PNG image to EPS/PDF with sam2p.

    2. Include converted EPS or PDF in your document as usual. Every pixel will be just a small rectangular box, it will look crisp and sharp, and will scale without interpolation.

    For example, let's assume we have a small raster image, that we want to show:

    10×10

    We can convert it to vector PDF with this command:

    sam2p 10x10.png PDF: 10x10.pdf
    

    Now as we have a vector version (where every pixel is a rectangular), we can include it in whatever LaTeX document and scale freely. All pixels will scale, but will not be interpolated.

    For example,

    \documentclass[12pt]{article}
    \usepackage[papersize={4cm,4cm},margin=2pt]{geometry}
    \usepackage{graphicx}
    
    \begin{document}
    \includegraphics[width=0.8\linewidth]{10x10.pdf}
    \end{document}
    

    This will look like this:

    10×10 scaled without interpolation

    Drawbacks:

    • PDF version of the image is likely to be several times bigger than its original PNG version.