The shell escape feature (\write18) can be used to call external programs during the compilation. The following example first checks, if the file is present. If it is missing, then it calls wget to download the file if pdflatex was called with enabled shell escape feature, e.g. via option -shell-escape or -enable-write18 (MiKTeX).
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\IfFileExists{profile-pics-16.jpg}{%
}{%
\immediate\write18{%
wget http://www.qqxxzx.com/images/profile-pics/profile-pics-16.jpg%
}%
}
\includegraphics{profile-pics-16.jpg}
\end{figure}
\end{document}
In case of LuaTeX, shell escape is not necessary, because the downloading can be done by library luasocket.
The following example defines macro \Download, which takes the file name and the URL. If LuaTeX is detected, the downloading is handled in Lua. Otherwise shell escape is needed. For convenience, the file name is stored in macro \DownloadFile for the later use in \includegraphics.
\documentclass{article}
\usepackage{graphicx}
\usepackage{ifluatex}
\ifluatex
\directlua{
tex.enableprimitives('', {'luaescapestring'})
}
\newcommand*{\Download}[2]{%
\IfFileExists{#1}{%
}{%
\directlua{
local io = require('io')
local http = require('socket.http')
local ltn12 = require('ltn12')
local file_name = '\luaescapestring{#1}'
local url = '\luaescapestring{#2}'
texio.write_nl('Downloading: ' .. file_name)
texio.write_nl('')
http.request{
url=url,
sink=ltn12.sink.file(io.open(file_name, 'w'))
}
}%
}%
\edef\DownloadFile{#1}%
}
\else
\newcommand*{\Download}[2]{%
\IfFileExists{#1}{%
}{%
\immediate\write18{%
wget -O "#2" "#1"%
}%
}%
\edef\DownloadFile{#1}%
}%
\fi
\begin{document}
\begin{figure}
\centering
\Download{profile-pics-16.jpg}{%
http://www.qqxxzx.com/images/profile-pics/profile-pics-16.jpg%
}
\includegraphics{\DownloadFile}
\end{figure}
\end{document}
Caution: The code does not check for any download errors.
latexcan find it. – wilx Sep 24 '16 at 08:16pdflatexas long as you load the following two packages:\usepackage{graphicx}and\usepackage{hyperref}. If that does not resolve your issue, please compose a fully compilable MWE including\documentclassand the appropriate packages that reproduces the problem. – Peter Grill Sep 24 '16 at 08:57--shell-escapeflag on. – Werner Sep 24 '16 at 15:40