Saving in a html webdialog? I’m not sure I fully understand that question.
You want to preview the result without using a WebDialog? (Why do you not want to use a WebDialog?)
In your example snippet you save two times - why is that?
You can’t display an image without first making a file to display - even if it’s temporary…
So use something a bit like the first example, to make a temporary image file.
Then with some simple html show that file in a SketchUp webdialog.
But you don’t even need to do that…
Make the temporary image file, then use something like: UI.openURL("file::///#{full_path_to_image}")
It will then open that image in whatever your system has set up to display that image type - jpg, png etc
You can send the data as base64 to the webdialog - and use a data URI to display the image: Data URLs - HTTP | MDN
However, there is no API method to get an image of the view without saving. So you have to use some form of temp file for that. But if you want to delete the temp file as quickly as possible you can read it, delete the temp file… Then base64 encode the content and pass it into the webdialog which inserts it as a data URI.