@takazudo/zudo-image-tweaker 0.1.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +57 -0
  4. package/dist/blurhash/index.d.ts +35 -0
  5. package/dist/blurhash/index.js +40 -0
  6. package/dist/browser/exif-orientation.d.ts +12 -0
  7. package/dist/browser/index.d.ts +7 -0
  8. package/dist/browser/index.js +160 -0
  9. package/dist/browser/orientation-semantics.d.ts +37 -0
  10. package/dist/browser/orientation.d.ts +25 -0
  11. package/dist/browser/prepare-upload.d.ts +100 -0
  12. package/dist/budget/index.d.ts +73 -0
  13. package/dist/budget/index.js +157 -0
  14. package/dist/calibrate/index.d.ts +129 -0
  15. package/dist/calibrate/index.js +206 -0
  16. package/dist/composite/index.d.ts +50 -0
  17. package/dist/composite/index.js +56 -0
  18. package/dist/exif/index.d.ts +41 -0
  19. package/dist/exif/index.js +100 -0
  20. package/dist/heif/index.d.ts +139 -0
  21. package/dist/heif/index.js +275 -0
  22. package/dist/index.d.ts +14 -0
  23. package/dist/index.js +68 -0
  24. package/dist/ogp/index.d.ts +72 -0
  25. package/dist/ogp/index.js +117 -0
  26. package/dist/presets-PTxNoMdy.js +630 -0
  27. package/dist/product-photo/index.d.ts +50 -0
  28. package/dist/product-photo/index.js +189 -0
  29. package/dist/product-photo/shadow.d.ts +48 -0
  30. package/dist/run-BIjGA2Fu.js +22 -0
  31. package/dist/square/index.d.ts +98 -0
  32. package/dist/square/index.js +89 -0
  33. package/dist/variants/engine.d.ts +38 -0
  34. package/dist/variants/feature-detect.d.ts +8 -0
  35. package/dist/variants/hash-cache.d.ts +63 -0
  36. package/dist/variants/heic.d.ts +15 -0
  37. package/dist/variants/index.d.ts +5 -0
  38. package/dist/variants/index.js +19 -0
  39. package/dist/variants/presets.d.ts +18 -0
  40. package/dist/variants/repair.d.ts +28 -0
  41. package/dist/variants/run.d.ts +36 -0
  42. package/dist/variants/tags.d.ts +13 -0
  43. package/dist/variants/types.d.ts +208 -0
  44. package/package.json +126 -0
@@ -0,0 +1,117 @@
1
+ import { randomUUID as B } from "node:crypto";
2
+ import { writeFile as L, rename as U, rm as b } from "node:fs/promises";
3
+ import u from "node:path";
4
+ import s from "sharp";
5
+ const l = 1200, p = 630, R = 600, F = 0, H = 45, I = 0.1, S = 0.3, x = 0.2, M = 0.25, P = 0.25, Y = 0.25, j = 24, k = 8, m = 85, w = !0, N = 1.5;
6
+ async function q(e, t, o) {
7
+ const { topGradientOpacity: r, bottomGradientOpacity: a, gradientTopHeight: i, gradientBottomHeight: n } = o, c = Math.round(t * i), d = Math.round(t * (1 - n)), h = `
8
+ <svg width="${e}" height="${t}" xmlns="http://www.w3.org/2000/svg">
9
+ <defs>
10
+ <linearGradient id="topGradient" x1="0%" y1="0%" x2="0%" y2="100%">
11
+ <stop offset="0%" style="stop-color:black;stop-opacity:${r}" />
12
+ <stop offset="100%" style="stop-color:black;stop-opacity:0" />
13
+ </linearGradient>
14
+ <linearGradient id="bottomGradient" x1="0%" y1="0%" x2="0%" y2="100%">
15
+ <stop offset="0%" style="stop-color:black;stop-opacity:0" />
16
+ <stop offset="100%" style="stop-color:black;stop-opacity:${a}" />
17
+ </linearGradient>
18
+ </defs>
19
+ <rect x="0" y="0" width="${e}" height="${c}" fill="url(#topGradient)" />
20
+ <rect x="0" y="${d}" width="${e}" height="${t - d}" fill="url(#bottomGradient)" />
21
+ </svg>
22
+ `;
23
+ return s(Buffer.from(h)).png().toBuffer();
24
+ }
25
+ async function C(e, t, o, r) {
26
+ const { shadowBlur: a, shadowOpacity: i, cornerRadius: n, shadowOffsetY: c } = r, d = Math.round((e - o) / 2), h = Math.round((t - o) / 2) + c, f = `
27
+ <svg width="${e}" height="${t}" xmlns="http://www.w3.org/2000/svg">
28
+ <defs>
29
+ <filter id="blur" x="-50%" y="-50%" width="200%" height="200%">
30
+ <feGaussianBlur in="SourceGraphic" stdDeviation="${a}" />
31
+ </filter>
32
+ </defs>
33
+ <rect
34
+ x="${d}"
35
+ y="${h}"
36
+ width="${o}"
37
+ height="${o}"
38
+ rx="${n}"
39
+ ry="${n}"
40
+ fill="black"
41
+ opacity="${i}"
42
+ filter="url(#blur)"
43
+ />
44
+ </svg>
45
+ `;
46
+ return s(Buffer.from(f)).png().toBuffer();
47
+ }
48
+ async function W(e, t) {
49
+ const o = `
50
+ <svg width="${e}" height="${e}" xmlns="http://www.w3.org/2000/svg">
51
+ <rect x="0" y="0" width="${e}" height="${e}" rx="${t}" ry="${t}" fill="white" />
52
+ </svg>
53
+ `;
54
+ return s(Buffer.from(o)).png().toBuffer();
55
+ }
56
+ async function y(e, t, o, r) {
57
+ const a = await s(e).metadata(), i = {
58
+ buffer: e,
59
+ width: a.width ?? t,
60
+ height: a.height ?? o,
61
+ format: "jpeg"
62
+ };
63
+ if (r) {
64
+ const n = u.join(
65
+ u.dirname(r),
66
+ `.${u.basename(r)}.${B()}.tmp`
67
+ );
68
+ try {
69
+ await L(n, e), await U(n, r);
70
+ } catch (c) {
71
+ throw await b(n, { force: !0 }), c;
72
+ }
73
+ i.path = r;
74
+ }
75
+ return i;
76
+ }
77
+ async function z(e, t = {}) {
78
+ const o = t.width ?? l, r = t.height ?? p, a = t.foregroundSize ?? Math.min(R, o, r), i = Math.min(o, r);
79
+ if (a > i)
80
+ throw new Error(
81
+ `foregroundSize (${a}) exceeds the canvas limit of ${i}px (the smaller of width=${o} and height=${r}); the composite card cannot be larger than the canvas it is centered on.`
82
+ );
83
+ const n = t.cornerRadius ?? F, c = t.blurSigma ?? H, d = t.desaturate ?? I, h = t.quality ?? m, f = t.progressive ?? w, T = {
84
+ topGradientOpacity: t.topGradientOpacity ?? S,
85
+ bottomGradientOpacity: t.bottomGradientOpacity ?? x,
86
+ gradientTopHeight: t.gradientTopHeight ?? M,
87
+ gradientBottomHeight: t.gradientBottomHeight ?? P
88
+ }, O = {
89
+ shadowBlur: t.shadowBlur ?? j,
90
+ shadowOpacity: t.shadowOpacity ?? Y,
91
+ cornerRadius: n,
92
+ shadowOffsetY: t.shadowOffsetY ?? k
93
+ }, E = await s(e).rotate().resize(o, r, { fit: "cover", position: "center" }).blur(c).modulate({ saturation: 1 - d }).jpeg({ quality: 100 }).toBuffer(), [A, D] = await Promise.all([
94
+ q(o, r, T),
95
+ C(o, r, a, O)
96
+ ]), g = await s(e).rotate().resize(a, a, { fit: "cover", position: "center" }).png().toBuffer(), _ = n > 0 ? await s(g).composite([
97
+ { input: await W(a, n), blend: "dest-in" }
98
+ ]).png().toBuffer() : g, $ = Math.round((o - a) / 2), G = Math.round((r - a) / 2), v = await s(E).composite([
99
+ { input: A, blend: "over" },
100
+ { input: D, blend: "over" },
101
+ { input: _, left: $, top: G }
102
+ ]).jpeg({ quality: h, progressive: f, mozjpeg: !0 }).toBuffer();
103
+ return y(v, o, r, t.outPath);
104
+ }
105
+ async function Q(e, t = {}) {
106
+ const o = t.width ?? l, r = t.height ?? p, a = t.quality ?? m, i = t.progressive ?? w, n = await s(e).rotate().resize(o, r, { fit: "cover", position: "center" }).jpeg({ quality: a, progressive: i, mozjpeg: !0 }).toBuffer();
107
+ return y(n, o, r, t.outPath);
108
+ }
109
+ async function K(e, t = {}) {
110
+ const { landscapeThreshold: o = N, ...r } = t, a = await s(e).metadata(), i = a.autoOrient?.width ?? a.width ?? 1, n = a.autoOrient?.height ?? a.height ?? 1;
111
+ return i / n >= o ? { ...await Q(e, r), method: "landscape" } : { ...await z(e, r), method: "composite" };
112
+ }
113
+ export {
114
+ Q as generateOgpFromLandscape,
115
+ z as generateOgpImage,
116
+ K as generateSmartOgp
117
+ };