{"id":20542189,"url":"https://github.com/weivea/tinypng2","last_synced_at":"2026-04-21T14:01:45.136Z","repository":{"id":42968108,"uuid":"202856583","full_name":"weivea/tinypng2","owner":"weivea","description":"一个有点2的基于tinypng图片压缩服务的图片压缩工具；只支持png、JPEG格式图片，无需api key","archived":false,"fork":false,"pushed_at":"2022-12-11T02:17:59.000Z","size":113,"stargazers_count":1,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T04:29:22.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weivea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-17T08:38:39.000Z","updated_at":"2021-09-13T12:33:39.000Z","dependencies_parsed_at":"2023-01-26T13:15:15.365Z","dependency_job_id":null,"html_url":"https://github.com/weivea/tinypng2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weivea/tinypng2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ftinypng2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ftinypng2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ftinypng2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ftinypng2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/tinypng2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ftinypng2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32095160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T01:29:43.755Z","updated_at":"2026-04-21T14:01:45.094Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @weivea/tinypng2\n一个有点2的基于tinypng图片压缩服务的图片压缩工具；只支持png、JPEG格式图片，\n\n**重要的事情说三遍**\n**无需api key**\n**无需api key**\n**无需api key**\n\n\n稳定性依赖于当前网络环境访问 https://tinypng.com/ 的性能\n\n勉强能用~ 不要声张~\n\n**ps: 基于网络，无网络时无法使用**\n\n## require\n\nnode version \u003e=12.4.0\n\n## Install\n\n`npm install -g @weivea/tinypng2`\n\n## Usage\n\n```shell\ncd dirOfImage #进入指定目录\ntinypng2 *.(png|jpeg)\n```\n\n## use it as a module\n\n\n\n`npm install @weivea/tinypng2 --save`\n\n```javascript\nconst tinyPng = require('@weivea/tinypng2')\nconst imgReadStream = fs.createReadStream(filePath)\n\ntinyPng(imgReadStream).then((resultBuf)=\u003e{\n  // resultBuf 压缩后得图片，Buffer\n})\n\n// 用完后记得调用； tinyPng.close(),  tinyPng起了一个子进程来对 tinypng网站做爬虫\ntinyPng.close()\n```\n\n**ps: 只适用于单线程调用， tinyPng不能同时发起俩， 得在then回调之后再发起下一个，如下**\n\n```javascript\n\nrun(imagePaths).then(()=\u003e{\n  console.log('done')\n  tinyPng.close();\n}).catch((er)=\u003e{\n  console.error('run Error:', er)\n  tinyPng.close();\n})\n\nasync function run(filePaths) {\n  const len = filePaths.length\n  for (let i=0; i\u003clen; i++) {\n    const filePath = filePaths[i]\n    const imgReadStream = fs.createReadStream(filePath)\n    console.log('compress:', filePath)\n    const resultBuf = await tinyPng(imgReadStream)\n    // console.log(resultBuf)\n    const pathObj = path.parse(filePath);\n    pathObj.name = pathObj.name + '_tiny'\n    pathObj.base = ''\n    const newPath = path.format(pathObj)\n    // console.log(newPath)\n    const wStream = fs.createWriteStream(newPath) \n    const pass = new PassThrough()\n    pass.pipe(wStream)\n    pass.end(resultBuf)\n    console.log('compressed:', newPath)\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ftinypng2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Ftinypng2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ftinypng2/lists"}