Closed shenxxu720 closed 7 months ago
Hi shenxxu720,
The issue you are finding is because tinify.fromFile() is an asyncronous operation. The output is undefined because tinify.compressionCount is being executed before tinify.fromFile() is completed. You can try something like this:
const tinify = require("tinify");
tinify.key = "YOUR_API_KEY";
tinify.fromFile("panda.png").toFile("panda_compressed.png").then(() => {
console.log("Compression count:", tinify.compressionCount);
});
After I perform compression (tinify.fromFile()), the value of tinify.compressionCount is undefined. Can I get the quantity only in the callback of tinify.validate()?