4

I was happy to read that \includegraphics allows setting the interpolate flag for imported images:

\includegraphics[interpolate]{testimg}

This works wonderfully if testimg is a PNG image. Unfortunately, it does not work if testimg is a PDF image (example pdf image).

Is there any way to import PDF images and have their interpolate flag be true?

5
  • 1
    Any raster objects in a PDF are put inside a "container" so they appear "vectorized", since PDF is natively a vector format. (Not sure of the technical terminology here.) So, from the point of view of graphicx, the image is already vectorized, even though it's technically not. I think the only way to get interpolation in a PDF would be to produce it whenever the PDF is produced from the raster graphic. Or simply include the original raster graphic in a raster format supported by graphicx. TLDR: interpolate doesn't make sense for PDF because it is a vector format. Commented Mar 6, 2014 at 16:41
  • 1
    Use raster formats for raster images; use vector formats for vector images. Less trouble overall (even if you don't do this). Perhaps you can get the original, un-PDFed image, or somehow cut it out of the PDF.
    – vonbrand
    Commented Mar 6, 2014 at 19:00
  • @vonbrand: Which format would you suggest for B/W raster images? In my experience, PDF B/W images have smaller file sizes compared with PNG and GIF. I think that's because of ZIP compression in PDFs.
    – u17
    Commented Mar 6, 2014 at 19:08
  • Many (most?) PNG exporters have the ability to apply varying levels of compression to the image. The compression is always lossless, but the resulting size can vary considerably. For example, I saved the image you attached (which was a PNG), opened it up in IrfanView, and re-saved it as a second PNG with maximum compression. The file size shrunk by 47%. Commented Mar 6, 2014 at 19:50
  • @MikeRenfro: Fair enough, thanks. I think there is no general rule; on some B/W images, I do better with PDF on others with PNG. Image patterns or small files seem to favor PNG. Anyways, if PDF interpolate is not implemented in LaTeX, I'll either convert to PNG or keep two PDFs for every image, one with Interpolation, the other without. Not a major inconvenience (as of now).
    – u17
    Commented Mar 6, 2014 at 20:08

1 Answer 1

2

Expanding my comment into an answer:

Any raster objects in a PDF are put inside a container so they appear vectorized, since PDF is natively a vector format. So from the point of view of graphicx, the image is already vectorized, even though it's technically not, only encapsulated by a vector format.

The only way to get interpolation in a PDF would be to produce it before the PDF is produced from the raster graphic. Or simply include the original raster graphic in a raster format supported by graphicx, with appropriate compression applied if needed.

The example requires --shell-escape, ImageMagick, and a copy of example-image-a.png (from the mwe package) placed in the same directory as the example's .tex file:

\documentclass{article}
\usepackage{mwe}
\setkeys{Gin}{width=0.75in}

\begin{document}
\immediate\write18{convert example-image-a.png fromraster.pdf}
\includegraphics{image-a.png}
\includegraphics[interpolate]{fromraster}
\includegraphics[interpolate]{image-a.png}
\includegraphics{image-a.pdf}
\includegraphics[interpolate]{image-a.pdf}
\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .