How to convert an HTML file with referenced images on the command line to a webarchive? Under macOS I want to convert HTML files with referenced images on the command line/programatically to webarchives.

Given a sample file sample.html containing:

&lt;html&gt;&lt;body&gt;
&lt;h1&gt;File with resource&lt;/h1&gt;
&lt;p&gt;This file shows text and references an image.&lt;/p&gt;
&lt;img src="sample.jpg" /&gt;
&lt;/body&gt;&lt;/html&gt;


and an image sample.jpg in the same directory, I can view the html file in any browser and it is render with the image. To convert to a webarchive I tried:

textutil -convert webarchive sample.html


but the resulting sample.webarchive does not, when opened in Safari, render the image - though it contains it (see comments).

How can I do the conversion from the command line correctly, so that the result contains and renders the image? After all that's what webarchives are for!
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.