Where are cut-n-pasted graphics stored in the .scriv package?

A technical question for those of you who know the “inner workings” of the .scriv package file.

When I store a graphical image (like a .png file) in a Folder in the Binder, the file gets stored in .scriv/Files/Data/UUID/content.png.

When I store text in a Text document in the Binder, the text gets stored in .scriv/Files/Data/UUID/content.rtf.

But what happens when I create a Text document in the Binder, type some text, and cut-n-paste a .png file into that document? If I locate the corresponding .scriv/Files/Data/UUID/content.rtf, only the text is stored in there. (No graphical image.) There is no corresponding graphical image file for the cut-n-pasted image that I can find anywhere in .scriv/Files/Data.

So… Where is it stored? And how does Scrivener keep track of the image to know where to show it in that Text document in the Binder?

Thanks for the help!

In this case the image is stored inside of the content.rtf file (encoded). Open it with an external text editor and look for jpegblip or pngblip (or just blip), followed by a big pile of hex stuff. That’s your image.

Ah! Interesting.

Previously, I had checked content.rtf using TextEdit.app, the default app for .rtf files on my computer, but the image didn’t appear.

Now, I opened content.rtf using Word, and I can see the image easily.

And I opened it in a plain text editor and located the pngblip section… That’s great! Now, I have to figure out how to decode it!

Ah, that’s the easy part. Should be a simple Base64 decode. Actually… maybe not. I’d have to tinker with it. Could be a matter of hexadecimal → binary conversion. (Something like this.)

So, basically, you know the image file type (the part before the blip), you take the pile of hex stuff and convert it to binary, and then you store it in yourimage.filetype.

See also: RTF specification

2 Likes

Yup, works. Gave it a quick try in PHP, out came the image I pasted into Scrivener:

<?php

$strHexBlip = "..."; // the stuff between "blip" and "}}"

$binImage = hex2bin($strHexBlip);
$resFile = fopen("blip2img.png", "w");
fwrite($resFile, $binImage);
fclose($resFile);

?>
1 Like

Note that Scrivener includes quite a few extensions beyond what TextEdit supports. And in some cases (like footnotes), TextEdit will simply throw away content that it doesn’t understand.

For this reason (among others), directly opening Scrivener’s content.rtf files in another application is not supported or recommended.

1 Like

Good to know! Do you have any documentation of Scrivener’s data standards for the data stored in the .rtf? I’m curious how the specific features are “stored” in the .rtf.

On further reflection, it would probably be more accurate to say that TextEdit is limited than that Scrivener extends the format. (Which was created by Microsoft.) I don’t think we’ve done anything that would baffle a full-featured editor like Nisus Pro or Word.

1 Like

Got it. Thanks very much.