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

How to get size of tinified images #26

Open
theahmadzai opened this issue Aug 24, 2020 · 3 comments
Open

How to get size of tinified images #26

theahmadzai opened this issue Aug 24, 2020 · 3 comments

Comments

@theahmadzai
Copy link

How to get metadata of images, size before and after tinification are there any methods available on node.js API, I'm sorry I searched a lot but couldn't find useful resources. If anyone could help?

@mattijsvandruenen
Copy link

@theahmadzai the API returns both the input size (before compression) and output size (after compression), but in the nodejs library we currently don't have a function available to get the input size. Feel free to add it and provide a pull request. You can refer to the documentation on https://tinypng.com/developers/reference for the API calls available via HTTP.

We do have a function available in the nodejs library to get the size of the compressed image. A simple example of printing it is

const source = tinify.fromUrl("https://tinypng.com/images/panda-happy.png");
source.result().size(function(err, size) {
  console.log(size);
});

To get the size before compression it might be easiest to use the filesystem module within nodejs.

@theahmadzai
Copy link
Author

Thanks, I'm tinkering with the library.
I have a question, why is upload from file response object key different from upload from URL i.e
upload from file returns

{
  "input": {
    "size": 207565,
    "type": "image/jpeg"
  }
}

while uploading from URL returns

{
  "output": {
    "size": 30734,
    "type": "image/png"
  }
}

@mattijsvandruenen
Copy link

@theahmadzai it looks like the documentation on https://tinypng.com/developers/reference isn't complete in regards to the json returned for some API calls. If you give any of those curl commands a try you will see that for both upload from file and url return a response including both input and output, like:

{
  "input": {
    "size": 76606,
    "type": "image/jpeg"
  },
  "output": {
    "size": 41892,
    "type": "image/jpeg",
    "width": 480,
    "height": 600,
    "ratio": 0.5469,
    "url": "https://api.tinify.com/output/..."
  }
}

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