mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Edge Function example on image manipulation (#29658)
* chore: add magick-wasm example functions * chore: add image manipulation guide
This commit is contained in:
1 parent
58b599b037
commit
ef6353e84c
3 files changed
+125
No files matched your search
@@ -0,0 +1,43 @@
|
||||
// This is an example showing how to use Magick WASM to do image manipulations in Edge Functions.
|
||||
//
|
||||
import {
|
||||
ImageMagick,
|
||||
initializeImageMagick,
|
||||
MagickFormat,
|
||||
} from "npm:@imagemagick/magick-wasm@0.0.30";
|
||||
|
||||
const wasmBytes = await Deno.readFile(
|
||||
new URL(
|
||||
"magick.wasm",
|
||||
import.meta.resolve("npm:@imagemagick/magick-wasm@0.0.30"),
|
||||
),
|
||||
);
|
||||
await initializeImageMagick(
|
||||
wasmBytes,
|
||||
);
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const formData = await req.formData();
|
||||
const content = await formData.get("file").bytes();
|
||||
|
||||
let result = ImageMagick.read(
|
||||
content,
|
||||
(img): Uint8Array => {
|
||||
// resize the image
|
||||
img.resize(500, 300);
|
||||
// add a blur of 60x5
|
||||
img.blur(60, 5);
|
||||
|
||||
return img.write(
|
||||
(data) => data,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return new Response(
|
||||
result,
|
||||
{ headers: { "Content-Type": "image/png" } },
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user