Create stamps outside of Tiled

I’m migrating my map editing over to Tiled but a bunch of my premade “stamps” from my old system I want to import into Tiled without having to recreate them, because there’s a few hundred. I was looking at the file format but I can’t seem to find a way to decode the data in the .stamp file. Is this even possible?

Looking at the file:

        "compression": "zlib",
        "data": "eJyzZmBgsAbiOiRsjUOsjggMAEwnCIo=",
        "encoding": "base64",

I’ve tried various orders to decode & uncompress but don’t end up with anything obviously usable. Is there a simple way to re-create the data so that I can import all my stamps?

Maybe this page in the documentation helps:

https://doc.mapeditor.org/en/stable/reference/global-tile-ids/

The stamps are essentially stored using the JSON format, wrapped in another JSON object to store variations and their probability (btw, eventually we’d like to make the stamps editable and probably abandon this custom format in favor of just a JSON map).

Anyway, that data first needs to be base64-decoded and then zlib-decompressed, and then they’re binary unsigned 32-bit integers in little-endian byte order.

That was exactly what I was looking for, thanks!

Edit: In case anyone else is looking for a way to do this, here is a snipped of PHP code I used. You should be able to easily implement this into any other language.

# the JSON specifies how many rows and columns
# you need to specify all the tiles in the brush (this is a 2x2 square, top left to bottom right)
$tiles = [144, 144, 144, 145];

$packed = '';
foreach ($tiles as $tile) {
    # V = unsigned long (always 32 bit, little endian byte order)
    $packed .= pack('V', $tile);
}

# also worked with ZLIB_ENCODING_GZIP, but did not work with ZLIB_ENCODING_RAW
$zlibEncoded = zlib_encode($packed, ZLIB_ENCODING_DEFLATE);

# here is your data
$base64Encoded = base64_encode($zlibEncoded);

If you have the old .stamp files, you should be able to drop them into your new stamps directory and they should work, provided the tilesets still exist.