@soga/imgutils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/main.d.mts +49 -0
- package/dist/main.d.ts +49 -0
- package/dist/main.js +1 -0
- package/dist/main.mjs +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# no desc
|
package/dist/main.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SpawnOptions } from 'child_process';
|
|
2
|
+
|
|
3
|
+
declare function getMetadata(filePath: string): Promise<{
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
type: string;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
declare class Compress {
|
|
10
|
+
private ffmpeg_path;
|
|
11
|
+
private output_root;
|
|
12
|
+
private meta;
|
|
13
|
+
private is_heic;
|
|
14
|
+
private input_path;
|
|
15
|
+
private output_filename;
|
|
16
|
+
constructor({ ffmpeg_path }: {
|
|
17
|
+
ffmpeg_path: string;
|
|
18
|
+
});
|
|
19
|
+
protected ffmpeg(args: string[], options?: SpawnOptions): Promise<unknown>;
|
|
20
|
+
start({ input_path, output_path, }: {
|
|
21
|
+
input_path: string;
|
|
22
|
+
output_path: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
private generateFile;
|
|
25
|
+
}
|
|
26
|
+
declare const compress: ({ input_path, output_path, ffmpeg_path, }: {
|
|
27
|
+
input_path: string;
|
|
28
|
+
output_path: string;
|
|
29
|
+
ffmpeg_path: string;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
|
|
32
|
+
declare class Combine {
|
|
33
|
+
start({ inputs, output_path, col, width, height, }: {
|
|
34
|
+
inputs: string[];
|
|
35
|
+
output_path: string;
|
|
36
|
+
col: number;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
declare const combine: (params: {
|
|
42
|
+
inputs: string[];
|
|
43
|
+
output_path: string;
|
|
44
|
+
col: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
|
|
49
|
+
export { Combine, Compress, combine, compress, getMetadata };
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SpawnOptions } from 'child_process';
|
|
2
|
+
|
|
3
|
+
declare function getMetadata(filePath: string): Promise<{
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
type: string;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
declare class Compress {
|
|
10
|
+
private ffmpeg_path;
|
|
11
|
+
private output_root;
|
|
12
|
+
private meta;
|
|
13
|
+
private is_heic;
|
|
14
|
+
private input_path;
|
|
15
|
+
private output_filename;
|
|
16
|
+
constructor({ ffmpeg_path }: {
|
|
17
|
+
ffmpeg_path: string;
|
|
18
|
+
});
|
|
19
|
+
protected ffmpeg(args: string[], options?: SpawnOptions): Promise<unknown>;
|
|
20
|
+
start({ input_path, output_path, }: {
|
|
21
|
+
input_path: string;
|
|
22
|
+
output_path: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
private generateFile;
|
|
25
|
+
}
|
|
26
|
+
declare const compress: ({ input_path, output_path, ffmpeg_path, }: {
|
|
27
|
+
input_path: string;
|
|
28
|
+
output_path: string;
|
|
29
|
+
ffmpeg_path: string;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
|
|
32
|
+
declare class Combine {
|
|
33
|
+
start({ inputs, output_path, col, width, height, }: {
|
|
34
|
+
inputs: string[];
|
|
35
|
+
output_path: string;
|
|
36
|
+
col: number;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
declare const combine: (params: {
|
|
42
|
+
inputs: string[];
|
|
43
|
+
output_path: string;
|
|
44
|
+
col: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
|
|
49
|
+
export { Combine, Compress, combine, compress, getMetadata };
|
package/dist/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t,e=Object.create,a=Object.defineProperty,i=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,r=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,n=(t,e,r,n)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let p of s(e))o.call(t,p)||p===r||a(t,p,{get:()=>e[p],enumerable:!(n=i(e,p))||n.enumerable});return t},p={};((t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})})(p,{Combine:()=>b,Compress:()=>_,combine:()=>j,compress:()=>w,getMetadata:()=>h}),module.exports=(t=p,n(a({},"__esModule",{value:!0}),t));var u=require("image-size/fromFile");async function h(t){return await(0,u.imageSizeFromFile)(t)}var c=require("fs-extra"),f=require("path"),l=require("uuid"),m=((t,i,s)=>(s=null!=t?e(r(t)):{},n(!i&&t&&t.__esModule?s:a(s,"default",{value:t,enumerable:!0}),t)))(require("heic-convert")),g=require("child_process"),_=class{ffmpeg_path;output_root;meta;is_heic=!1;input_path="";output_filename="";constructor({ffmpeg_path:t}){this.ffmpeg_path=t}async ffmpeg(t,e){const a=this.ffmpeg_path;return await new Promise((i,s)=>{const r=(0,g.spawn)(a,t,Object.assign({stdio:"ignore"},e));r.on("close",t=>{i(t)}),r.on("error",t=>{s(t)})})}async start({input_path:t,output_path:e}){this.meta=await h(t);const{type:a}=this.meta,i=(0,f.parse)(e),s=i.base,r=i.dir;if(this.output_root=r,this.output_filename=s,"svg"==a){const e=(0,f.join)(r,s);await(0,c.copy)(t,e)}else if("heic"==a){this.is_heic=!0;const e=(0,l.v4)()+".png",a=(0,f.join)(r,e);this.input_path=a;const i=await(0,c.readFile)(t),s=await(0,m.default)({buffer:i,format:"PNG",quality:1});await(0,c.writeFile)(a,s)}else this.input_path=t;await this.generateFile()}async generateFile(){const t=this.input_path;if(!t)return;const e=["-i",t],{width:a,height:i}=this.meta;if(a/i>1){const t=Math.min(1080,2*Math.ceil(i/2));e.push("-vf",`scale=-2:${t}:flags=lanczos`)}else{const t=Math.min(1920,2*Math.ceil(a/2));e.push("-vf",`scale=${t}:-2:flags=lanczos`)}e.push("-y",this.output_filename),await this.ffmpeg(e,{cwd:this.output_root}),this.is_heic&&await(0,c.remove)(this.input_path)}},w=async({input_path:t,output_path:e,ffmpeg_path:a})=>{const i=new _({ffmpeg_path:a});await i.start({input_path:t,output_path:e})},y=require("fs-extra"),d=require("jimp"),b=class{async start({inputs:t,output_path:e,col:a,width:i,height:s}){const r=i*a,o=s*Math.ceil(t.length/a),n=new d.Jimp({width:r,height:o});for(let e=0;e<t.length;e++){const r=e%a*i,o=Math.floor(e/a)*s,p=await d.Jimp.read(t[e]);n.composite(p,r,o)}const p=await n.getBuffer("image/jpeg",{quality:70});await(0,y.writeFile)(e,p)}},j=async t=>{const e=new b;await e.start(t)};
|
package/dist/main.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{imageSizeFromFile as t}from"image-size/fromFile";async function a(a){return await t(a)}import{copy as i,readFile as e,remove as s,writeFile as o}from"fs-extra";import{join as p,parse as h}from"path";import{v4 as n}from"uuid";import r from"heic-convert";import{spawn as c}from"child_process";var f=class{ffmpeg_path;output_root;meta;is_heic=!1;input_path="";output_filename="";constructor({ffmpeg_path:t}){this.ffmpeg_path=t}async ffmpeg(t,a){const i=this.ffmpeg_path;return await new Promise((e,s)=>{const o=c(i,t,Object.assign({stdio:"ignore"},a));o.on("close",t=>{e(t)}),o.on("error",t=>{s(t)})})}async start({input_path:t,output_path:s}){this.meta=await a(t);const{type:c}=this.meta,f=h(s),u=f.base,m=f.dir;if(this.output_root=m,this.output_filename=u,"svg"==c){const a=p(m,u);await i(t,a)}else if("heic"==c){this.is_heic=!0;const a=n()+".png",i=p(m,a);this.input_path=i;const s=await e(t),h=await r({buffer:s,format:"PNG",quality:1});await o(i,h)}else this.input_path=t;await this.generateFile()}async generateFile(){const t=this.input_path;if(!t)return;const a=["-i",t],{width:i,height:e}=this.meta;if(i/e>1){const t=Math.min(1080,2*Math.ceil(e/2));a.push("-vf",`scale=-2:${t}:flags=lanczos`)}else{const t=Math.min(1920,2*Math.ceil(i/2));a.push("-vf",`scale=${t}:-2:flags=lanczos`)}a.push("-y",this.output_filename),await this.ffmpeg(a,{cwd:this.output_root}),this.is_heic&&await s(this.input_path)}},u=async({input_path:t,output_path:a,ffmpeg_path:i})=>{const e=new f({ffmpeg_path:i});await e.start({input_path:t,output_path:a})};import{writeFile as m}from"fs-extra";import{Jimp as l}from"jimp";var _=class{async start({inputs:t,output_path:a,col:i,width:e,height:s}){const o=Math.ceil(t.length/i),p=new l({width:e*i,height:s*o});for(let a=0;a<t.length;a++){const o=a%i*e,h=Math.floor(a/i)*s,n=await l.read(t[a]);p.composite(n,o,h)}const h=await p.getBuffer("image/jpeg",{quality:70});await m(a,h)}},g=async t=>{const a=new _;await a.start(t)};export{_ as Combine,f as Compress,g as combine,u as compress,a as getMetadata};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soga/imgutils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "dist/main.js",
|
|
9
|
+
"types": "dist/main.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"demo": "tsx ./demo/demo",
|
|
15
|
+
"build": "rimraf dist && tsup src/main.ts --format cjs,esm --dts --minify terser",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsup": "^8.5.0",
|
|
20
|
+
"@types/fs-extra": "^11.0.4",
|
|
21
|
+
"rimraf": "^6.0.1",
|
|
22
|
+
"typescript": "^5.8.3",
|
|
23
|
+
"@soga/typescript-config": "latest",
|
|
24
|
+
"tsx": "^4.20.6",
|
|
25
|
+
"@types/heic-convert": "^2.1.0",
|
|
26
|
+
"terser": "^5.43.1"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [],
|
|
29
|
+
"author": "",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"fs-extra": "^11.3.2",
|
|
33
|
+
"jimp": "^1.6.0",
|
|
34
|
+
"@soga/fileutils": "latest",
|
|
35
|
+
"uuid": "^11.1.0",
|
|
36
|
+
"heic-convert": "^2.1.0",
|
|
37
|
+
"image-size": "^2.0.2"
|
|
38
|
+
}
|
|
39
|
+
}
|