How to convert an HTML file with referenced images on the command line to a webarchive?
Use the tool webarchiver (which you can install via brew install webarchiver):

webarchiver -url sample.html -output sample.webarchive


The webarchive produced contains the image and Safari shows the image when it displays the webarchive.