Can I use image compression in the middle of this? #1081
Answered
by
donmccurdy
neciszhang
asked this question in
Q&A
-
|
Hi, I want to use image compression, like tinypng, when converting gltf to glb. This can greatly reduce the model size. I want to know how I should do the conversion in the middle. |
Beta Was this translation helpful? Give feedback.
Answered by
donmccurdy
Sep 5, 2023
Replies: 1 comment 2 replies
-
|
If you're using the glTF Transform CLI, then the commands below will apply OxiPNG and MozJPEG optimization to PNG and JPEG images. Use both if your model contains both formats. gltf-transform png input.gltf output.glb
gltf-transform jpeg output.glb output.glbSee Alternatively, the same things can be done in a script with the textureCompress() function. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps Sharp will work in a browser someday (partial progress in lovell/sharp#3522) but it doesn't yet. textureCompress() works in a browser in v3.6, just omit the encoder argument, but it is limited to compressing with the browser's own PNG/JPEG codecs. I don't think you'll find that it helps very much, unless the (a) the original compression on the images was fairly poor, or (b) you're converting to a more efficient format like WebP.
If you are aware of an image compression library you'd like to use instead, then you might be better off just writing that function yourself. See #853 (comment) for an example of how this could be done.