-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set background color for jpg? #33
Comments
In fact, now that I think of it, how do you control options for the engine in general? The docs say you should consult the engine, which I understand is So are there options for quality, etc., as well? |
That should be possible with |
https://github.com/twolfson/gmsmith/tree/0.4.5#canvasexportoptions-cb |
@twolfson So No I don't need aliasing, I want to sprite a bunch of jpgs. If I output a jpg sprite then its size is 10% that of a png. But of course png has alpha channel, and jpg does not, hence the need to set the bg color for jpg. I dug into It uses jpeg-js under the cover, which seems to set bg color via the canvas before superimposing an image on it (I think), but there doesn't seem a configurable way to get at that part of the code. So it doesn't seem possible. |
It's definitely possible. In https://github.com/twolfson/pixelsmith/blob/1.0.0/lib/canvas.js#L13 Since jpeg's don't support transparency, the alpha channel is dropped and it becomes To support your use case, we can fill all of those values with specific https://www.npmjs.com/package/ndarray-fill I will take a look at adding in support by the end of this weekend. |
@twolfson Sure, what I meant is not that it's not possible (whoa too many double negative there), but there was no configurable way for me to do it, save a mod to the underlying source. If you decide to look into it, maybe consider having it as an option, so a user can pass in an (optional) rgba value? That would make it useful to the greatest number of people. I think black and white are the most used, but might as well make it configable? Now I understand what you meant in that other thread, about maintainability. So many interconnected projects, wow! |
Taking a shot at this now |
I added it in via {
// imgName, cssName,
imgOpts: {
background: [255, 255, 255, 255] // opaque white
}
} |
The upgrade has been installed in |
@twolfson Works well on this side... thanks!
|
Eh, |
@twolfson Yes you're right... didn't test it properly. |
Interesting since we use https://github.com/twolfson/pixelsmith/blob/1.1.0/test/pixelsmith-test.js#L109 https://github.com/twolfson/pixelsmith/blob/1.1.0/test/expected-files/background.jpeg I am going to double check with a white background and PNG to verify supporting all cases. |
Ah, nvm. Saw your edit =) |
It auto generates a sprite with a black background. Since I use padding between images, and need to place the images on a white background, I need that bleed area to be white.
There is no documentation, so I dug through the source. From
gulp.spritesmith
tospritesmith
topixelsmith
tosave-pixels
... :)Is this possible?
The text was updated successfully, but these errors were encountered: