tinify / tinify-nodejs

Node.js client for the Tinify API.
https://tinypng.com/developers
MIT License
423 stars 74 forks source link

are there any docs on the convert functionality? #40

Closed johnnyreilly closed 2 years ago

johnnyreilly commented 2 years ago

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:

      .convert({type:["image/webp", "image/jpg"]})

https://github.com/tinify/tinify-nodejs/pull/39/files#diff-887779faeffe0d98f0035c4daf646e3c83f535e4ae53943482026ea8b19f923bR91

Does this mean convert to webp from jpeg?

ddmicu commented 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!

johnnyreilly commented 2 years ago

It does!

johnnyreilly commented 2 years ago

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?

ddmicu commented 2 years ago

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);

johnnyreilly commented 2 years ago

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 {

https://github.com/tinify/tinify-nodejs/blob/95e52888045dd42d67b79f4175cf6ab33f284710/src/tinify/Source.ts#L88

Would you welcome a PR which made the type more explicit based on the details you've provided in this chat?

johnnyreilly commented 2 years ago

Have raised a speculative PR here: https://github.com/tinify/tinify-nodejs/pull/41

ddmicu commented 2 years ago

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!

johnnyreilly commented 2 years ago

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