In the first version of 1Quest, I had a somewhat more complex system, with wall casting shadows on other tiles. I don't have any screenshot accessible here, but you can watch the video
https://www.youtube.com/watch?v=gUTuM6-DnYc (at 15 seconds)
My way of dealing with it was looking at the 4 tiles around:
3 2 1
4 X 0
5 6 7
So I looked upon 0 2 4 and 6 (I use trigonometric order) and compute a simple string composed of 0 for non-wall and 1 for wall in that order
So for example
###
.##
...
would be 1100 (wall in 0 and 2, no wall in 4 and 6). And then I directly named my assets with this string in the names (cavewall_0011.png for this wall in caves) so I just have to create the asset name dynamically. You can check that it makes 16 different tiles and I needed the 16 for what I wanted.
I had to add special additional name for upper left and right corner, because if tile 1 or 3 and non wall, but 0 and 2 (2 and 4 resp.) are walls, you must add additional small corner to make things nice. So cavewall_0011 may add another graphic cavewall_UR.png for adding the upper right corner.
In top of that, I add a last "_0", "_1" etc... at the end for the different version of the same tile (to avoid repetition)