94

I have tried

\includegraphics{http://www.site.com/path/to/figure.png}

But this returns the error

ERROR: Package pdftex.def Error: File
`http://www.website.com/path/to/figure.png'
not found.

Are there other options?

2
  • 13
    ConTeXt supports this natively. \externalfigure[http://www.site.com/path/to/figure.png] just works. Behind the scenes, ConTeXt downloads the file to the luatex cache once, and from then on just reuses the figure.
    – Aditya
    Nov 16, 2010 at 4:36
  • 2
    do you want to add this as an answer? That way, I can select it. Nov 16, 2010 at 5:07

3 Answers 3

72

you could use \write18 and a curl or wget script to grab the image from the web and download it to your directory.

\documentclass{article}
\usepackage{graphicx} % includegraphics command is implemented here
\begin{document}

\write18{wget http://www.some-site.com/path/to/image.png}
\includegraphics{image.png}

\end{document}

note however, that recent versions of miktex and texlive come with restricted versions of \write18, and it some cases you must pass an option to latex to enable it, as in:

pdflatex --shell-escape test.tex
4
  • could you please provide example code in your answer? I did not realize that it was possible to use bash code within latex, although I do use Sweave so I can understand the principle. Nov 15, 2010 at 22:04
  • nice! I guess that this underscores the point that I only need to download the image once in any case. But this approach seems like it would help with portability. Nov 16, 2010 at 3:09
  • 26
    \IfFileExists{image.png}{}{\write18{...}} would help with the only-downloading-once problem. Nov 16, 2010 at 9:06
  • 1
    Could this be done programmatically somehow, maybe with a \renewcommand such that includegraphics can just take the url as an argument?
    – cboettig
    Oct 9, 2012 at 1:23
43

Short answer: no. You will need to download the image and use it locally if you want to include it in your document. pdfTeX and XeTeX do not include the necessary code to grab an image from an arbitrary location.

Of course, you can link to an image at at remote location. You can make use of the hyperref package to include a suitable link. You might do this using a bit of text:

\href{http://somewhere.com/someplace/some.jpg}{picture here}

or by downloading a local copy and then pointing to the online version

\href{http://somewhere.com/someplace/some.jpg}{\incudegraphics{some.jpg}}

I note from the comments that LuaTeX does include the necessary library to download a copy of an image itself. That would make inclusion possible directly, but I don't know of a pre-build solution for LuaLaTeX. I guess that would be a separate answer in any case.

3
  • I am not sure if I understand, it seems to me that your short answer contradicts your second answer. And, could you please provide an example of how can I use hyperref to do this? Nov 16, 2010 at 3:07
  • @David: I've added a bit more detail
    – Joseph Wright
    Nov 16, 2010 at 7:07
  • 1
    I'm trying this kind of reference, but it seems to fail - has the relevant functionality been removed? (I'm getting a "some.jpg is missing" error) May 14, 2013 at 17:48
7

(Copying from the comments section)

ConTeXt supports this natively:

http://wiki.contextgarden.net/What_is_ConTeXt

The following:

\externalfigure[http://www.site.com/path/to/figure.png] 

just works. Behind the scenes, ConTeXt downloads the file to the luatex cache once, and from then on just reuses the figure.


My additional notes:

  • If you have MacTeX, you don't need to do any extra installation. Just change the typesetting option inside your TeX editor.
  • I couldn't get this to work in TeXShop, but it works fine in TeXWorks. Also, I had to use ConTeXt (LuaTeX). It didn't work when I tried ConTeXt (pdfTeX).
2
  • Well, this doesn't answer the question which is about embedding a remote image file using LaTeX.
    – AlexG
    Jan 5, 2016 at 8:06
  • But it does solve what the user is trying to do, which he explicitly said he is happy to mark as correct. And I started using ConTeXt as a result of what the comment said. Please read up on the XY problem (meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Jan 10, 2016 at 7:36

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.