Skip to content
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

are there any docs on the convert functionality? #40

Closed
johnnyreilly opened this issue Oct 3, 2022 · 8 comments
Closed

are there any docs on the convert functionality? #40

johnnyreilly opened this issue Oct 3, 2022 · 8 comments

Comments

@johnnyreilly
Copy link

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
Copy link
Contributor

ddmicu commented Oct 4, 2022

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:

  • One image type, specified as a string "image/webp".
  • Multiple image types, specified as an array ["image/webp","image/png"]. The smallest of the provided image types will be returned.
  • The wildcard "*/*" returns the smallest of Tinify's supported image types, currently JPEG, PNG and WebP.

.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:

  • A hex value. Custom background color using the color's hex value: "#D02670".
  • "white" or "black". Only the colors white and black are supported as strings.
    You must specify a background color if you wish to convert an image with a transparent background to an image type which does not support transparency (like JPEG).

Hope this helps!

@ddmicu ddmicu closed this as completed Oct 4, 2022
@johnnyreilly
Copy link
Author

It does!

@johnnyreilly
Copy link
Author

johnnyreilly commented Oct 4, 2022

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
Copy link
Contributor

ddmicu commented Oct 4, 2022

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
Copy link
Author

johnnyreilly commented Oct 4, 2022

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 {

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?

@johnnyreilly
Copy link
Author

Have raised a speculative PR here: #41

@ddmicu
Copy link
Contributor

ddmicu commented Oct 4, 2022

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants