[Tex/LaTex] includegraphics without file extension

graphics

How can I use includegraphics when I want to include an image which has no extension?

When I try to set type=jpg by hand I get the following error:
LaTeX Error: Cannot determine size of graphic in images/posters/sample (no size specified)

If I change the sample to sample.jpg all works, but I have a bunch of theses images for which I cannot change the suffix (another application depends on it).

Any advice?

Best Answer

I can't think of a simple solution, but here's a possible solution that adapts the internals command used by \includegraphics.

\documentclass{article}
\usepackage{graphicx} 

\makeatletter
\newcommand{\jpg@Ginclude@graphics}[1]{%
  \begingroup
   \let\input@path\Ginput@path
   \filename@parse{#1}%
   \def\Gin@ext{.jpg}%
   \def\Gin@base{\filename@area\filename@base}%
   \Gread@jpg{\Gin@base}%
   \Gin@viewport@code\Gin@nat@height\Gin@ury bp%
   \advance\Gin@nat@height-\Gin@lly bp%
   \Gin@nat@width \Gin@urx bp%
   \advance\Gin@nat@width-\Gin@llx bp%
   \Gin@req@sizes
   \expandafter\ifx\csname Ginclude@jpg\endcsname\relax
     \Gin@drafttrue
     \expandafter\ifx\csname Gread@jpg\endcsname\relax
       \@latex@error {Can not include graphics of type: jpg}\@ehc
       \global\let\Gread@jpg\@empty
     \fi
   \fi
   \leavevmode
   \ifGin@draft
     \hb@xt@
     \Gin@req@width{\vrule \hss \vbox to \Gin@req@height{\hrule \@width
      \Gin@req@width \vss
      \edef\@tempa{\Gin@base}%
      \rlap{\ttfamily\expandafter\strip@prefix\meaning\@tempa}%
       \vss\hrule}\hss\vrule
     }%
   \else
    \@addtofilelist{\Gin@base}%
    \ProvidesFile{\Gin@base}[Graphic file (type jpg)]%
    \setbox\z@\hbox{\Ginclude@jpg{\Gin@base}}%
    \dp\z@\z@\ht\z@\Gin@req@height\wd\z@\Gin@req@width\box\z@
   \fi
  \endgroup
}%

\newcommand{\includejpgnoext}[2][]{%
 \begingroup
  \let\Ginclude@graphics\jpg@Ginclude@graphics
  \includegraphics[#1]{#2}%
 \endgroup
}

\makeatother

\begin{document}
\includejpgnoext{sample} % jpg image file called 'sample' with no extension   
\end{document}

It only works with PDFLaTeX.