5

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...

Community
  • 1
  • 1
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
  • Maybe the blurriness changes with small adjustments to the resize value? – Charles Stewart Mar 31 '10 at 10:20
  • what resize algorithm are you using? and why don't you just scale using latex? what's wrong with that? – Mica Mar 31 '10 at 16:09
  • Yeah, it comes out blurry when rescaling with LaTeX - according to the other post on SO regarding this issue, it was recommended that other programs be used to resize. In imagemagick I am using the default resizing algorithm... And regarding the blurriness changes with small adjustments, that didn't seem to work either - – hatmatrix Mar 31 '10 at 21:13
  • If you're using pdflatex, the image is not scaled by LaTeX at all, it's just included in the PDF as-is. If it looks crappy, maybe try another viewer? Adobe Reader, in spite of all its flaws, does a good job at image scaling. – Thomas Apr 01 '10 at 14:18
  • Oh, I see - yes, Adobe Reader is definitely better than Preview... but I guess all depends on whether their scaling is better than what I can do a priori... – hatmatrix Apr 05 '10 at 05:49

1 Answers1

4

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.
Community
  • 1
  • 1
sastanin
  • 40,473
  • 13
  • 103
  • 130