1

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?

  • 1
    If you cannot change the original name of the image you could use a link/alias/whatever this is called on your OS with the name sample.jpg that links to sample. – user36296 Jul 25 '17 at 12:57
  • Sure, but the problem is I am including images from another system, and would prefer to avoid the overhead of copying / linking to images. Moreover, I have thousands of said images... – nir Jul 25 '17 at 13:06
  • Generating the links can be automated ... – user36296 Jul 25 '17 at 13:07
  • Call me lazy, but I would think there is a simple solution inside Latex – nir Jul 25 '17 at 13:10
  • b.t.w, tried adding "\DeclareGraphicsExtensions{.pdf,.png,.jpg,}% Note the trailing ',' which defines an empty extension", but still am getting an error – nir Jul 25 '17 at 13:10
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.