On export to save tilesets with used only tiles from it

Is there a automatic way to export (compact) tilesets into one from compacting only used tile parts that are used inside of project?
For example i have 30 tilesets i use them all but i do not use everything in them and maybe ill use other part of them in the future. On export (game preparation) is there a way to automatically export 30 tiles sets to 1 with “used only” tiles remapped with new position on export?

Basically i need to save some space and i was wondering is there an automated way to do it, or im stuck with doing it by hand.

You might want to try tmxOptimizer or tileset_baker. Note however that both have not been updated in years, so they may need some adjustments. They also may not do exactly what you want of course, but it can be a starting point anyway.

Tiled itself currently has no such functionality, but it would be a great feature to contribute. Please don’t do this kind of stuff by hand!

I couldn’t get tmxOptimizer to work, so I wrote my own in modern Python:

Currently only supports one layer, one tileset, one map format (CSV), but I’ll probably be adding multi-layer and multi-tileset support soon as I’ll need it for a game map I’m working on. Open to bribes, of course.

@eishiya suggested rewriting in JavaScript so it could run within Tiled, which would be great if someone wants to grab this idea and run with it. I hate working in JavaScript. :wink: