I might need further clarification on this one, but you are setting the file_location variable with the capture, so the variable’s value will always exist.
Also, I’m not sure what the | file_exists filter is? I don’t think that’s supported in Treepl.
As far as I’m aware, there is no way in Treepl’s Liquid to tell if a file exists (at least not for a non-text based file).
Perhaps instead define your image in a Site Global (or other module). Then your Liquid condition to check if a value has been set or not would be like this:
I have set page headers in a number of ways, mostly using a custom module for headers. However, you could accomplish this with the File API. It looks like you are matching the page name to the image file name.