@greatapps/common 1.1.449 → 1.1.450
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.
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
PhotonImage,
|
|
3
|
-
resize,
|
|
4
|
-
crop,
|
|
5
|
-
SamplingFilter
|
|
6
|
-
} from "@cf-wasm/photon/edge-light";
|
|
7
|
-
function processImage(input) {
|
|
1
|
+
async function processImage(input) {
|
|
8
2
|
const {
|
|
9
3
|
imageBytes,
|
|
10
4
|
targetWidth,
|
|
@@ -12,6 +6,7 @@ function processImage(input) {
|
|
|
12
6
|
outputFormat = "jpeg",
|
|
13
7
|
quality = 85
|
|
14
8
|
} = input;
|
|
9
|
+
const { PhotonImage, resize, crop, SamplingFilter } = await import("@cf-wasm/photon/edge-light");
|
|
15
10
|
const image = PhotonImage.new_from_byteslice(imageBytes);
|
|
16
11
|
try {
|
|
17
12
|
const sourceWidth = image.get_width();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/images/services/image-processing.service.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/images/services/image-processing.service.ts"],"sourcesContent":["import type { ProcessImageInput, ProcessImageOutput } from '../types/image.type'\n\nexport async function processImage(input: ProcessImageInput): Promise<ProcessImageOutput> {\n const {\n imageBytes,\n targetWidth,\n targetHeight,\n outputFormat = 'jpeg',\n quality = 85,\n } = input\n\n // Dynamic import to avoid fs.createReadStream error in edge runtime\n const { PhotonImage, resize, crop, SamplingFilter } = await import(\n '@cf-wasm/photon/edge-light'\n )\n\n const image = PhotonImage.new_from_byteslice(imageBytes)\n\n try {\n const sourceWidth = image.get_width()\n const sourceHeight = image.get_height()\n const targetAspect = targetWidth / targetHeight\n const sourceAspect = sourceWidth / sourceHeight\n\n let cropX1 = 0\n let cropY1 = 0\n let cropX2 = sourceWidth\n let cropY2 = sourceHeight\n\n if (sourceAspect > targetAspect) {\n const cropWidth = Math.round(sourceHeight * targetAspect)\n cropX1 = Math.round((sourceWidth - cropWidth) / 2)\n cropX2 = cropX1 + cropWidth\n } else if (sourceAspect < targetAspect) {\n const cropHeight = Math.round(sourceWidth / targetAspect)\n cropY1 = Math.round((sourceHeight - cropHeight) / 2)\n cropY2 = cropY1 + cropHeight\n }\n\n const cropped = crop(image, cropX1, cropY1, cropX2, cropY2)\n const resized = resize(\n cropped,\n targetWidth,\n targetHeight,\n SamplingFilter.Triangle\n )\n\n let outputBytes: Uint8Array\n switch (outputFormat) {\n case 'jpeg':\n outputBytes = resized.get_bytes_jpeg(quality)\n break\n case 'png':\n outputBytes = resized.get_bytes()\n break\n case 'webp':\n outputBytes = resized.get_bytes_webp()\n break\n default:\n outputBytes = resized.get_bytes_jpeg(quality)\n }\n\n cropped.free()\n resized.free()\n\n return {\n bytes: outputBytes,\n width: targetWidth,\n height: targetHeight,\n format: `image/${outputFormat}`,\n }\n } finally {\n image.free()\n }\n}\n"],"mappings":"AAEA,eAAsB,aAAa,OAAuD;AACxF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,UAAU;AAAA,EACZ,IAAI;AAGJ,QAAM,EAAE,aAAa,QAAQ,MAAM,eAAe,IAAI,MAAM,OAC1D,4BACF;AAEA,QAAM,QAAQ,YAAY,mBAAmB,UAAU;AAEvD,MAAI;AACF,UAAM,cAAc,MAAM,UAAU;AACpC,UAAM,eAAe,MAAM,WAAW;AACtC,UAAM,eAAe,cAAc;AACnC,UAAM,eAAe,cAAc;AAEnC,QAAI,SAAS;AACb,QAAI,SAAS;AACb,QAAI,SAAS;AACb,QAAI,SAAS;AAEb,QAAI,eAAe,cAAc;AAC/B,YAAM,YAAY,KAAK,MAAM,eAAe,YAAY;AACxD,eAAS,KAAK,OAAO,cAAc,aAAa,CAAC;AACjD,eAAS,SAAS;AAAA,IACpB,WAAW,eAAe,cAAc;AACtC,YAAM,aAAa,KAAK,MAAM,cAAc,YAAY;AACxD,eAAS,KAAK,OAAO,eAAe,cAAc,CAAC;AACnD,eAAS,SAAS;AAAA,IACpB;AAEA,UAAM,UAAU,KAAK,OAAO,QAAQ,QAAQ,QAAQ,MAAM;AAC1D,UAAM,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA,eAAe;AAAA,IACjB;AAEA,QAAI;AACJ,YAAQ,cAAc;AAAA,MACpB,KAAK;AACH,sBAAc,QAAQ,eAAe,OAAO;AAC5C;AAAA,MACF,KAAK;AACH,sBAAc,QAAQ,UAAU;AAChC;AAAA,MACF,KAAK;AACH,sBAAc,QAAQ,eAAe;AACrC;AAAA,MACF;AACE,sBAAc,QAAQ,eAAe,OAAO;AAAA,IAChD;AAEA,YAAQ,KAAK;AACb,YAAQ,KAAK;AAEb,WAAO;AAAA,MACL,OAAO;AAAA,MACP,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,QAAQ,SAAS,YAAY;AAAA,IAC/B;AAAA,EACF,UAAE;AACA,UAAM,KAAK;AAAA,EACb;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PhotonImage,
|
|
3
|
-
resize,
|
|
4
|
-
crop,
|
|
5
|
-
SamplingFilter,
|
|
6
|
-
} from '@cf-wasm/photon/edge-light'
|
|
7
1
|
import type { ProcessImageInput, ProcessImageOutput } from '../types/image.type'
|
|
8
2
|
|
|
9
|
-
export function processImage(input: ProcessImageInput): ProcessImageOutput {
|
|
3
|
+
export async function processImage(input: ProcessImageInput): Promise<ProcessImageOutput> {
|
|
10
4
|
const {
|
|
11
5
|
imageBytes,
|
|
12
6
|
targetWidth,
|
|
@@ -15,6 +9,11 @@ export function processImage(input: ProcessImageInput): ProcessImageOutput {
|
|
|
15
9
|
quality = 85,
|
|
16
10
|
} = input
|
|
17
11
|
|
|
12
|
+
// Dynamic import to avoid fs.createReadStream error in edge runtime
|
|
13
|
+
const { PhotonImage, resize, crop, SamplingFilter } = await import(
|
|
14
|
+
'@cf-wasm/photon/edge-light'
|
|
15
|
+
)
|
|
16
|
+
|
|
18
17
|
const image = PhotonImage.new_from_byteslice(imageBytes)
|
|
19
18
|
|
|
20
19
|
try {
|