I avoided to overload \includegraphics and defined a new command that, when label is not specified among the keys, behaves exactly as \includegraphics.
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{xparse}
\ExplSyntaxOn
\keys_define:nn { miguel/label }
{
label .tl_set:N = \l_miguel_label_tl,
unknown .code:n = \clist_put_right:Nx \l_miguel_label_clist
{ \l_keys_key_tl = \exp_not:n { #1 } }
}
\clist_new:N \l_miguel_label_clist
\box_new:N \l_miguel_label_box
\box_new:N \l_miguel_label_image_box
\NewDocumentCommand{\xincludegraphics}{O{}m}
{
\tl_clear:N \l_miguel_label_tl
\clist_clear:N \l_miguel_label_clist
\keys_set:nn { miguel/label } { #1 }
\tl_if_empty:NTF \l_miguel_label_tl
{
\miguel_includegraphics:Vn \l_miguel_label_clist { #2 }
}
{
\hbox_set:Nn \l_miguel_label_image_box
{
\miguel_includegraphics:Vn \l_miguel_label_clist { #2 }
}
\hbox_set:Nn \l_miguel_label_box
{
\skip_horizontal:n { 3pt }
\fcolorbox{white}{white}{\footnotesize \tl_use:N \l_miguel_label_tl}
}
\leavevmode
\box_use:N \l_miguel_label_image_box
\skip_horizontal:n { -\box_wd:N \l_miguel_label_image_box }
\hbox_overlap_right:n
{
\box_move_up:nn
{
\box_ht:N \l_miguel_label_image_box -
\box_ht:N \l_miguel_label_box - 3pt
}
{ \box_use_drop:N \l_miguel_label_box }
}
\skip_horizontal:n { \box_wd:N \l_miguel_label_image_box }
}
}
\cs_new_protected:Nn \miguel_includegraphics:nn
{
\includegraphics[#1]{#2}
}
\cs_generate_variant:Nn \miguel_includegraphics:nn { V }
\ExplSyntaxOff
\begin{document}
\begin{table}[htp]
\centering
\xincludegraphics[scale=0.3,label=a)]{example-image-a}
\xincludegraphics[scale=0.3,label=b)]{example-image-b}
\xincludegraphics[scale=0.2,angle=90,label=c)]{example-image-c}
\end{table}
\end{document}

Here is an improved version that accepts also the keys
pos = nw | n | ne | e | se | s | sw | w
labelbox = true | false
fontsize = <fontsize command>
The default value for fontsize is \footnotesize; it should be clear what to change for modifying the default. If one says labelbox, the label will be printed on a white background. This can be overridden with labelbox=false (if \setlabel{labelbox} has been used, see the example).
There is also a \setlabel command that can be used to set some keys, keeping the value in the current scope.
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{xparse,xcoffins}
\ExplSyntaxOn
\NewCoffin\imagecoffin
\NewCoffin\labelcoffin
\keys_define:nn { miguel/label }
{
label .tl_set:N = \l_miguel_label_tl,
labelbox .bool_set:N = \l_miguel_label_box_bool,
labelbox .default:n = true,
fontsize .tl_set:N = \l_miguel_label_size_tl,
fontsize .initial:n = \footnotesize,
pos .choice:,
pos/nw .code:n = \tl_set:Nn \l_miguel_label_pos_tl { left,up },
pos/ne .code:n = \tl_set:Nn \l_miguel_label_pos_tl { right,up },
pos/sw .code:n = \tl_set:Nn \l_miguel_label_pos_tl { left,down },
pos/se .code:n = \tl_set:Nn \l_miguel_label_pos_tl { right,down },
pos/n .code:n = \tl_set:Nn \l_miguel_label_pos_tl { hc,up },
pos/w .code:n = \tl_set:Nn \l_miguel_label_pos_tl { left,vc },
pos/s .code:n = \tl_set:Nn \l_miguel_label_pos_tl { hc,down },
pos/e .code:n = \tl_set:Nn \l_miguel_label_pos_tl { right,vc },
pos .initial:n = nw,
unknown .code:n = \clist_put_right:Nx \l_miguel_label_clist
{ \l_keys_key_tl = \exp_not:n { #1 } }
}
\clist_new:N \l_miguel_label_clist
\box_new:N \l_miguel_label_box
\box_new:N \l_miguel_label_image_box
\NewDocumentCommand{\xincludegraphics}{O{}m}
{
\group_begin:
\tl_clear:N \l_miguel_label_tl
\clist_clear:N \l_miguel_label_clist
\keys_set:nn { miguel/label } { #1 }
\tl_if_empty:NTF \l_miguel_label_tl
{
\miguel_includegraphics:Vn \l_miguel_label_clist { #2 }
}
{
\SetHorizontalCoffin\imagecoffin
{
\miguel_includegraphics:Vn \l_miguel_label_clist { #2 }
}
\SetHorizontalCoffin\labelcoffin
{
\raisebox{\depth}
{
\bool_if:NTF \l_miguel_label_box_bool
{ \fcolorbox{white}{white}{\l_miguel_label_size_tl\l_miguel_label_tl} }
{ \l_miguel_label_size_tl\l_miguel_label_tl }
}
}
\SetVerticalPole\imagecoffin{left}{3pt+\CoffinWidth\labelcoffin/2}
\SetVerticalPole\imagecoffin{right}{\Width-3pt-\CoffinWidth\labelcoffin/2}
\SetHorizontalPole\imagecoffin{up}{\Height-3pt-\CoffinHeight\labelcoffin/2}
\SetHorizontalPole\imagecoffin{down}{3pt+\CoffinHeight\labelcoffin/2}
\use:x{\JoinCoffins\imagecoffin[\l_miguel_label_pos_tl]\labelcoffin[vc,hc]}
\TypesetCoffin\imagecoffin
}
\group_end:
}
\NewDocumentCommand{\setlabel}{m}
{
\keys_set:nn { miguel/label } { #1 }
}
\cs_new_protected:Nn \miguel_includegraphics:nn
{
\includegraphics[#1]{#2}
}
\cs_generate_variant:Nn \miguel_includegraphics:nn { V }
\ExplSyntaxOff
\begin{document}
\begin{table}[htp]
\centering
\xincludegraphics[scale=0.3,label=a)]{example-image-a}
\xincludegraphics[scale=0.3,label=b)]{example-image-b}
\xincludegraphics[scale=0.2,angle=90,label=c),pos=sw,labelbox,fontsize=\Large]{example-image-c}
\xincludegraphics[scale=0.2,angle=90,label=c),pos=w,labelbox,fontsize=\tiny]{example-image-c}
\setlabel{pos=ne,fontsize=\scriptsize,labelbox}
\xincludegraphics[scale=0.2,angle=90,label=x)]{example-image-c}
\xincludegraphics[scale=0.2,angle=90,label=y),labelbox=false]{example-image-c}
\end{table}
\end{document}
subcaptionpackage. – Jesse op den Brouw Oct 10 '18 at 17:35