# Extract graphics symbol name in a delayed function? [duplicate]

Here's a simple "save as image" function:

saveImage[image_Graphics, format_String: "png", resolution_Real: 200] := Export[
TemplateApply[
"basename.format", <|
"basename" -> SymbolName[Unevaluated[image]],
"format" -> format|
>]
, image
, ImageResolution -> resolution
];


However, I can't make it hold the image name:

myImage = Plot[x, {x, 0, 1}]

saveImage@myImage (* evaluates image to be a Graphics object instead of the symbol *)


What do I do wrong?

• Take a look at HoldFirst but then you need to change image_Graphics as you expect _Symbol. – Kuba May 21 '18 at 20:56
• @Kuba: indeed this solves the problem. – Adobe May 21 '18 at 21:05

In order to use Unevaluated, saveImage must be held when calling saveImage. So I give saveImage the attribute HoldFirst. From now on, pattern matching won't work anymore for the first argument. That's why I added /; Head[image] === Graphics at the end.

ClearAll[saveImage];
"basename.format", <|