@greatapps/common 1.1.449 → 1.1.451
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/dist/modules/images/actions/process-image.action.mjs +1 -1
- package/dist/modules/images/actions/process-image.action.mjs.map +1 -1
- package/dist/modules/images/services/image-processing.service.mjs +2 -7
- package/dist/modules/images/services/image-processing.service.mjs.map +1 -1
- package/package.json +1 -1
- package/src/modules/images/actions/process-image.action.ts +1 -1
- package/src/modules/images/services/image-processing.service.ts +6 -7
|
@@ -8,7 +8,7 @@ async function processImageAction(input) {
|
|
|
8
8
|
for (let i = 0; i < binaryString.length; i++) {
|
|
9
9
|
bytes[i] = binaryString.charCodeAt(i);
|
|
10
10
|
}
|
|
11
|
-
const result = processImage({
|
|
11
|
+
const result = await processImage({
|
|
12
12
|
imageBytes: bytes,
|
|
13
13
|
targetWidth: input.targetWidth,
|
|
14
14
|
targetHeight: input.targetHeight
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/images/actions/process-image.action.ts"],"sourcesContent":["'use server'\n\nimport { processImage } from '../services/image-processing.service'\nimport type {\n ProcessImageActionInput,\n ProcessImageActionOutput,\n} from '../types/image.type'\n\nexport async function processImageAction(\n input: ProcessImageActionInput\n): Promise<ProcessImageActionOutput> {\n try {\n const base64Data = input.base64Image.replace(/^data:image\\/\\w+;base64,/, '')\n const binaryString = atob(base64Data)\n const bytes = new Uint8Array(binaryString.length)\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i)\n }\n\n const result = processImage({\n imageBytes: bytes,\n targetWidth: input.targetWidth,\n targetHeight: input.targetHeight,\n })\n\n const base64Output = btoa(String.fromCharCode(...result.bytes))\n\n return {\n success: true,\n base64Image: `data:${result.format};base64,${base64Output}`,\n }\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Erro ao processar imagem',\n }\n }\n}\n"],"mappings":";AAEA,SAAS,oBAAoB;AAM7B,eAAsB,mBACpB,OACmC;AACnC,MAAI;AACF,UAAM,aAAa,MAAM,YAAY,QAAQ,4BAA4B,EAAE;AAC3E,UAAM,eAAe,KAAK,UAAU;AACpC,UAAM,QAAQ,IAAI,WAAW,aAAa,MAAM;AAChD,aAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,YAAM,CAAC,IAAI,aAAa,WAAW,CAAC;AAAA,IACtC;AAEA,UAAM,SAAS,aAAa;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/images/actions/process-image.action.ts"],"sourcesContent":["'use server'\n\nimport { processImage } from '../services/image-processing.service'\nimport type {\n ProcessImageActionInput,\n ProcessImageActionOutput,\n} from '../types/image.type'\n\nexport async function processImageAction(\n input: ProcessImageActionInput\n): Promise<ProcessImageActionOutput> {\n try {\n const base64Data = input.base64Image.replace(/^data:image\\/\\w+;base64,/, '')\n const binaryString = atob(base64Data)\n const bytes = new Uint8Array(binaryString.length)\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i)\n }\n\n const result = await processImage({\n imageBytes: bytes,\n targetWidth: input.targetWidth,\n targetHeight: input.targetHeight,\n })\n\n const base64Output = btoa(String.fromCharCode(...result.bytes))\n\n return {\n success: true,\n base64Image: `data:${result.format};base64,${base64Output}`,\n }\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Erro ao processar imagem',\n }\n }\n}\n"],"mappings":";AAEA,SAAS,oBAAoB;AAM7B,eAAsB,mBACpB,OACmC;AACnC,MAAI;AACF,UAAM,aAAa,MAAM,YAAY,QAAQ,4BAA4B,EAAE;AAC3E,UAAM,eAAe,KAAK,UAAU;AACpC,UAAM,QAAQ,IAAI,WAAW,aAAa,MAAM;AAChD,aAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,YAAM,CAAC,IAAI,aAAa,WAAW,CAAC;AAAA,IACtC;AAEA,UAAM,SAAS,MAAM,aAAa;AAAA,MAChC,YAAY;AAAA,MACZ,aAAa,MAAM;AAAA,MACnB,cAAc,MAAM;AAAA,IACtB,CAAC;AAED,UAAM,eAAe,KAAK,OAAO,aAAa,GAAG,OAAO,KAAK,CAAC;AAE9D,WAAO;AAAA,MACL,SAAS;AAAA,MACT,aAAa,QAAQ,OAAO,MAAM,WAAW,YAAY;AAAA,IAC3D;AAAA,EACF,SAAS,OAAO;AACd,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,IAClD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -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 {
|