flother / spreet

Create a spritesheet from a set of SVG images
MIT License
81 stars 4 forks source link

File Input or SymLinks #81

Open Shikakka opened 5 months ago

Shikakka commented 5 months ago

Thanks for making this library! I previously used Spritezero in Javascript. Not the Spritezero-CLI version.

Here I could input a list of files instead of pointing to a folder. Would it be possible to implement something like this?

I probably have a weird use case, where I can upload to 3 different folders, for example: /sprites/public /sprites/version-a /sprites/version-a/part-b

where I want to generate a spritesheet for part-b, but including the sprites in public and version-a. But not including /sprites/version-a/part-a.

I tried to use Symbolic Links to create a new directory first /sprites/temp then create symbolic links to all .svgs. They work in other programs correctly.

But this gives me the error:

Error: cannot make a valid sprite name from "/sprites/temp/new-sprite.svg"

When i copy the files to the same folder, so no symlinks, they work correctly.

Shikakka commented 5 months ago

It would very much be a "nice to have" for now I just copy the files. What another option would be is input multiple folders.

Something like a comma seperation:

spreet --retina /sprites/public,/sprites/version-a,/sprites/version-a/part-b my_style@2x

But again it is a "nice to have" but probably not in scope of this project because of this very uncommon usecase.

flother commented 2 weeks ago

Sorry for the slow reply, I haven’t had a chance to look at Spreet for a while.

I previously used Spritezero in Javascript. Not the Spritezero-CLI version.

Here I could input a list of files instead of pointing to a folder. Would it be possible to implement something like this?

If it helps, Spreet can be used as a library too, just as Spritezero can — but of course you need to write Rust rather than JavaScript. If that’s something you’re comfortable with then it’s quite possible to build a spritesheet from SVGs spread across multiple directories. You can use the same pattern as Spreet itself does (start with the code, for example).

I tried to use Symbolic Links to create a new directory first /sprites/temp then create symbolic links to all .svgs. They work in other programs correctly.

But this gives me the error:

Error: cannot make a valid sprite name from "/sprites/temp/new-sprite.svg"

Oops! This is a bug. It should definitely be possible to use symlinked files. I’ve fixed this in 014ce6445790 and I’ll include it in the upcoming 0.12.0 release.

What another option would be is input multiple folders.

I’ve been thinking about this, and I think an interesting generic solution would be for Spreet to support using a config file. I like the idea of having a TOML file that would allow you to define multiple spritesheets that could be generated in one go. Hypothetically, something like:

[[sheets]]
ratio = 1
unique = true
minify-index-file = false
sprites = ["sprites/public", "sprites/version-a", "sprites/version-a/part-b"]
output = "sprites@1x.png"

[[sheets]]
ratio = 2
unique = true
minify-index-file = false
sprites = ["sprites/public", "sprites/version-a", "sprites/version-a/part-b"]
output = "sprites@2x.png"

Then you could perhaps run Spreet like:

spreet --config sprites.toml

But that’s for another time 😄. Until then, I hope 014ce6445790 fixes your immediate problem.