This commit is contained in:
parent
650f381148
commit
11fa3d1558
38 changed files with 819 additions and 148 deletions
27
src/services/images.ts
Normal file
27
src/services/images.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { asInt } from "@thi.ng/color-palettes";
|
||||
import { ARGB8888, canvasFromPixelBuffer, defIndexed, imageFromURL, intBufferFromImage } from "@thi.ng/pixel";
|
||||
import { ATKINSON, ditherWith } from "@thi.ng/pixel-dither";
|
||||
import { Data, Effect, pipe } from "effect";
|
||||
|
||||
class ImagesError extends Data.TaggedError("ImagesError")<{ cause: unknown }> {}
|
||||
|
||||
export class Images extends Effect.Service<Images>()("Images", {
|
||||
effect: Effect.gen(function*() {
|
||||
return {
|
||||
ditherImage: (image: HTMLImageElement, parent?: HTMLElement) =>
|
||||
Effect.gen(function*() {
|
||||
const buf = intBufferFromImage(image, ARGB8888).scale(0.8, "cubic");
|
||||
const theme = defIndexed(asInt(["salmon", "black"]));
|
||||
const ditheredBuf = ditherWith(ATKINSON, buf.copy(), {}).as(theme);
|
||||
|
||||
const canvas = canvasFromPixelBuffer(ditheredBuf, parent, { pixelated: true });
|
||||
return canvas;
|
||||
}),
|
||||
imageFromUrl: (url: URL) =>
|
||||
pipe(
|
||||
Effect.tryPromise(() => imageFromURL(url.toString())),
|
||||
Effect.mapError(e => new ImagesError({ cause: e.message })),
|
||||
),
|
||||
};
|
||||
}),
|
||||
}) {}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import type { SQLocalDrizzle } from "sqlocal/drizzle";
|
||||
|
||||
import v0000 from "@/db/drizzle/0000_open_the_twelve.sql?raw";
|
||||
import v0000 from "@/db/drizzle/0000_unusual_karen_page.sql?raw";
|
||||
import { Data, Effect } from "effect";
|
||||
|
||||
import { LocalSqlite } from "./db";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Layer, ManagedRuntime } from "effect";
|
||||
|
||||
import { LocalSqlite } from "./db";
|
||||
import { Images } from "./images";
|
||||
import { PrettyLogger } from "./logger";
|
||||
import { Migrations } from "./migrations";
|
||||
import { ReadApi } from "./read-api";
|
||||
|
|
@ -12,6 +13,7 @@ const MainLayer = Layer.mergeAll(
|
|||
Migrations.Default,
|
||||
ReadApi.Default,
|
||||
TmdbApi.Default,
|
||||
Images.Default,
|
||||
).pipe(Layer.provide(PrettyLogger));
|
||||
|
||||
export const RuntimeClient = ManagedRuntime.make(MainLayer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue