The following does mostly what you want, I think, but with a different command. If you really want to you can \RenewDocumentCommand \includegraphics ...
instead of \NewDocumentCommand \includegraphicslist ...
but I would not recommend doing so. Redefining \includegraphics
will almost certainly have unwanted side-effects. Worse, it may not cause those side-effects until later, by which time you will have forgotten you redefined it.
\documentclass[12pt]{article}% ateb: https://tex.stackexchange.com/a/713985/\usepackage{graphicx}\ExplSyntaxOn\seq_new:N \l__graphicslist_filelist_seq\tl_new:N \l__graphicslist_file_tl\cs_new_protected:Nn \graphicslist_includegraphics:nn{ \includegraphics [ #1 ] { #2 }}\cs_generate_variant:Nn \graphicslist_includegraphics:nn { nV }\cs_new_protected:Nn \graphicslist_includegraphicslist:nn{ \seq_set_from_clist:Nn \l__graphicslist_filelist_seq { #2 } \seq_get_left:NN \l__graphicslist_filelist_seq \l__graphicslist_file_tl \seq_map_inline:Nn \l__graphicslist_filelist_seq { \file_if_exist:nT { ##1 } { \seq_map_break:n { \tl_set:Nn \l__graphicslist_file_tl { ##1 } } } } \graphicslist_includegraphics:nV { #1 } \l__graphicslist_file_tl}\NewDocumentCommand \includegraphicslist { O {} m }{ \group_begin: \graphicslist_includegraphicslist:nn { #1 } { #2 } \group_end:}\ExplSyntaxOff\begin{document}\includegraphicslist[width=.3\textwidth]{example-image-a.pdf,example-image-b.pdf}\includegraphicslist[scale=.5]{example-image-x.pdf,example-image-a.pdf,example-image-b.pdf}\includegraphicslist[width=.2\textwidth,height=.5\textheight,keepaspectratio]{example-image-a.pdf,example-image-x.pdf}\end{document}
\includegraphicslist[]{}
is just like \includegraphics[]{}
except that the second argument may take a comma-separated list of file names and, whether it does so or not, the filename extension is mandatory. It would be possible to eliminate this requirement, but it is probably not worth the additional work.
If a list of file names is given, they should be listed in descending order of priority. If the first exists, all later names are ignored; likewise with the second and so forth.
The result of compiling the above is a line of example-image-a
s in different sizes. Given the result is utterly uninteresting and Okular/KDE has a new bug rendering any image I paste of very poor quality, I will refrain from inflicting an image on you at this time.