2

I have noticed that when including some EPS files, for whatever reason, the bounding box has been specified in quite a strange way (GIMP seems to be guilty of this, for instance).

I should probably just go through each file and correct these manually - but I have to ask, is there an automated way to do this without too much trouble?

I saw the package bmpsize, but it doesn't seem to work with EPS files.

This is problematic for me when when I use pdflatex with the epstopdf package instead of latex -> dvips -> ps2pdf. Rather than post a MWE, I pose the simple question, is there a way to override the bounding box to be (0, 0, width, height) for all included EPS images that include solely bitmaps?

EDIT: I have also noticed that the following solutions, though not wholly, automated, also do not work:

Equivalent of bounding box when compile with pdflatex (ps2eps still returns an incorrect bounding box).

bbarker
  • 1,177

1 Answers1

2

The following minimal example defines \check@includegraphics@ext{<filename>} (mostly taken from \Ginclude@graphics in graphics.dtx). It scans for all possible inclusions of <filename> as a graphic image. If a .bmp is found, you can supply additional default settings, otherwise it'll include the image with whatever you supplied:

enter image description here

\documentclass{article}
\usepackage{graphicx}

\makeatletter
\def\check@includegraphics@ext#1{%
  \begingroup
  \let\input@path\Ginput@path
  \filename@parse{#1}%
  \ifx\filename@ext\relax
    \@for\Gin@temp:=\Gin@extensions\do{%
      \ifx\Gin@ext\relax
        \Gin@getbase\Gin@temp
      \fi}%
  \else
    \Gin@getbase{\Gin@sepdefault\filename@ext}%
  \fi
  \xdef\filename@ext{\Gin@ext}%
  \endgroup}
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
  \check@includegraphics@ext{#2}% Find possible extension of graphics to be included
  \ifnum\pdfstrcmp{\filename@ext}{.bmp}=0 % BMP image
    \oldincludegraphics[#1,bb=0 0 10 10,clip=true]{#2}%
  \else
    \oldincludegraphics[#1]{#2}%
  \fi}
\makeatother

\begin{document}

\includegraphics[height=\baselineskip]{example-image-a}
\includegraphics[height=\baselineskip]{example-image-b.pdf}

\end{document}

As you can see, I've supplied a bounding box and clip=true, which you can modify to suit your requirements for a bitmap image inclusion.

Note that this conditioning is specific to a lowercase filename extension .bmp. Therefore, it would include a .BMP, .Bmp, ... in the usual way.

Werner
  • 603,163