Closed johnnyreilly closed 2 years ago
We are planning to update the documentation on our website asap but we are still in the process of releasing the new functionality in all the other Tinify API clients.
To answer your question, the example mentioned by you returns the smallest version of the image between webp and jpeg.
The following options are available as a type:
.transform: The transform object specifies the stylistic transformations that will be applied to your image. Include a background property to fill a transparent image's background. The following options are available to specify a background color:
Hope this helps!
It does!
Question: how do you know which type of image has been generated? If it can be jpg or webp, how do you know which it is?
We have some helper methods that you can use: content type (.mediaType()) or directly the extension as in the following example:
const source = tinify.fromFile("unoptimized.jpg"); const converted = source.convert({type:["image/webp","image/png"]}); const extension = converted.result().extension(); converted.toFile("converted-image." + extension);
Nice! I was looking at the types you're exposing on convert
and I can see it's just an object:
convert(options: object): Source {
Would you welcome a PR which made the type more explicit based on the details you've provided in this chat?
Have raised a speculative PR here: https://github.com/tinify/tinify-nodejs/pull/41
Thank you for the PR. We are planning to do the same for all our functions in the near future and we will review your changes in detail when we will get started.
One thing I've noted is the wildcard in my original comment was / but in reality is */* . I did not realise that in these comments I need to escape some characters. Sorry for the confusion!
One thing I've noted is the wildcard in my original comment was / but in reality is / . I did not realise that in these comments I need to escape some characters. Sorry for the confusion!
Haha! No worries - I've updated the PR to reflect
I can see the ability was added to convert images. Docwise I can't see anything, but I can see this code in the tests:
https://github.com/tinify/tinify-nodejs/pull/39/files#diff-887779faeffe0d98f0035c4daf646e3c83f535e4ae53943482026ea8b19f923bR91
Does this mean convert to
webp
fromjpeg
?