How to use the tinify.fromFile function in tinify

To help you get started, we’ve selected a few tinify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github herebefrogs / submersible-warship-2063 / scripts / tinify-pngs.js View on Github external
.forEach(async (png) => {
    const original = statSync(png).size;

    // TinyPNG
    const image = tinify.fromFile(png);
    await image.toFile(png);
    const optimized = statSync(png).size;

    // AdvPNG
    execSync(`advpng -l -4 ${png}`);
    const recompressed = statSync(png).size

    console.log(`${png} ${original} bytes -> TinyPNG ${optimized} bytes -> AdvPNG ${recompressed}`);

    // stage optimized PNG for inclusion in commit
    execSync(`git add ${png}`);
  });
github HuJiaoHJ / blog / tinify.js View on Github external
const task = file => {
    const source = tinify.fromFile(file.fromFile);
    source.toFile(file.toFile);
    return source._url;
}
// 通过输入文件夹和输出文件夹,返回一个数组
github semiromid / compress-images / test / node_modules / compress-images / index.js View on Github external
var source = tinifypng.fromFile(input);
                var copyrighted = source.preserve(enginepng.png.command[0]);
                copyrighted.toFile(output); 
              }else if(enginepng.png.command.length === 2){

                var source = tinifypng.fromFile(input);
                var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1]);
                copyrighted.toFile(output); 
              }else if(enginepng.png.command.length === 3){

                var source = tinifypng.fromFile(input);
                var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1], enginepng.png.command[2]);
                copyrighted.toFile(output); 
              }         
            }else{
              tinifypng.fromFile(input).toFile(output);
            }
        }          
      }else{
        console.log(colors.red("Don't [png] find ["+enginepng.png.engine+"] engine!"));
      }
    }
github semiromid / compress-images / test / node_modules / compress-images / index.js View on Github external
//- - - - - - - - - - - - -  - - - - - - - - - - -  
                }); 
              });
            }); 
            //-------------------------------------------------                   
        }else{
            var array;
            if(false != enginejpg.jpg.command){
              if(enginejpg.jpg.command.length === 1){

                var source = tinifyjpeg.fromFile(input);
                var copyrighted = source.preserve(enginejpg.jpg.command[0]);
                copyrighted.toFile(output); 
              }else if(enginejpg.jpg.command.length === 2){

                var source = tinifyjpeg.fromFile(input);
                var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
                copyrighted.toFile(output); 
              }else if(enginejpg.jpg.command.length === 3){

                var source = tinifyjpeg.fromFile(input);
                var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
                copyrighted.toFile(output); 
              }         
            }else{
              tinifyjpeg.fromFile(input).toFile(output);
            }
        }          
      }else{
        console.log(colors.red("Don't [jpg] find ["+enginejpg.jpg.engine+"] engine!"));
      }
    }
github semiromid / compress-images / index.js View on Github external
var source = tinifypng.fromFile(input);
                      var copyrighted = source.preserve(enginepng.png.command[0]);
                      copyrighted.toFile(output); 
                    }else if(enginepng.png.command.length === 2){

                      var source = tinifypng.fromFile(input);
                      var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1]);
                      copyrighted.toFile(output); 
                    }else if(enginepng.png.command.length === 3){

                      var source = tinifypng.fromFile(input);
                      var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1], enginepng.png.command[2]);
                      copyrighted.toFile(output); 
                    }         
                  }else{
                    tinifypng.fromFile(input).toFile(output);
                  }
              }

 
          
      }else{
        console.log(colors.red("Don't [png] find ["+enginepng.png.engine+"] engine!"));
      }
    }
github semiromid / compress-images / index.js View on Github external
var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0]);
                        copyrighted.toFile(output); 
                      }else if(enginejpg.jpg.command.length === 2){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
                        copyrighted.toFile(output); 
                      }else if(enginejpg.jpg.command.length === 3){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
                        copyrighted.toFile(output); 
                      }         
                    }else{
                      tinifyjpeg.fromFile(input).toFile(output);
                    }
                }
  

      }else{
        console.log(colors.red("Don't [jpg] find ["+enginejpg.jpg.engine+"] engine!"));
      }
    }
github semiromid / compress-images / index.js View on Github external
}else{
                            return callback(0, 0, 0, err);
                        }                            
                    }); 
                    //-------------------------------------------------                                 
                }else{
                    var array;
                    if(false != enginejpg.jpg.command){
                      if(enginejpg.jpg.command.length === 1){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0]);
                        copyrighted.toFile(output); 
                      }else if(enginejpg.jpg.command.length === 2){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
                        copyrighted.toFile(output); 
                      }else if(enginejpg.jpg.command.length === 3){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
                        copyrighted.toFile(output); 
                      }         
                    }else{
                      tinifyjpeg.fromFile(input).toFile(output);
                    }
                }
  

      }else{
        console.log(colors.red("Don't [jpg] find ["+enginejpg.jpg.engine+"] engine!"));
github CatchZeng / AppThinning / src / util / tinyPng / index.js View on Github external
.then(function(msg) {
        console.log(colors.green(msg))

        for (let index in images) {
          const image = images[index]
          console.log(colors.blue("compressing: " + image))
          tinify.fromFile(image).toFile(image, function(err, data) {
            if (err) {
              reject(new TinyPngError(err))
            } else {
              console.log(colors.green("compressed: " + image))

              compressedCount++
              if (compressedCount == images.length) {
                console.log(colors.green("finish tinyPng compression."))
                resolve(images)
              }
            }
          })
        }
      })
      .catch(function(err) {
github semiromid / compress-images / index.js View on Github external
return callback(size_in, size_output, percent, null); 
                                  //- - - - - - - - - - - - -  - - - - - - - - - - -  
                              }); 
                            });
                            //--------------------------------------
                        }else{
                            return callback(0, 0, 0, err);
                        }                            
                    }); 
                    //-------------------------------------------------                                 
                }else{
                    var array;
                    if(false != enginejpg.jpg.command){
                      if(enginejpg.jpg.command.length === 1){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0]);
                        copyrighted.toFile(output); 
                      }else if(enginejpg.jpg.command.length === 2){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
                        copyrighted.toFile(output); 
                      }else if(enginejpg.jpg.command.length === 3){

                        var source = tinifyjpeg.fromFile(input);
                        var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
                        copyrighted.toFile(output); 
                      }         
                    }else{
                      tinifyjpeg.fromFile(input).toFile(output);
                    }

tinify

Node.js client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis