imagetools - latest

This commit is contained in:
lovebird 2026-02-01 12:11:04 +01:00
parent 04b211d2a3
commit 21d9543dcd
7 changed files with 12 additions and 59 deletions

View File

@ -3212,14 +3212,6 @@
"integrity": "sha512-9a4/uxlTWJ4+a5i0ooc1rU7C7YOw3wT+UGqdeNNHWnOF9qcMBgLRS+4IYUqbczewFx4mLEig6gawh7X6mFlEkA==",
"license": "MIT"
},
"node_modules/undici-types": {
"version": "7.16.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
"dev": true,
"license": "MIT",
"optional": true
},
"node_modules/universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",

View File

@ -1,7 +1,5 @@
// @ts-check
import util from "node:util";
import potrace from "potrace";
import getSrcset from "./getSrcset.js";
import { sharp } from "../../utils/runtimeChecks.js";
@ -26,20 +24,7 @@ export default async function getFallbackImage(
return dataUri;
}
case "tracedSVG": {
const { function: fn, options } = formatOptions.tracedSVG;
const traceSVG = util.promisify(potrace[fn]);
const imageBuffer = sharp
? await image.toBuffer()
: Buffer.from(
(await image.encode(`image/${format === "jpg" ? "jpeg" : format}`))
.data
);
const tracedSVG = await traceSVG(imageBuffer, options);
return `data:image/svg+xml;utf8,${tracedSVG}`;
return `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" style="background: rgb(0,0,0)"></svg>`;
}
case "dominantColor": {
if (sharp) {

View File

@ -1,13 +1,14 @@
// @ts-check
import {
builtins,
loadImage,
applyTransforms,
generateTransforms,
} from "imagetools-core";
export {
loadImage
} from "imagetools-core";
import sharp from "sharp";
export const loadImage = (path) => sharp(path);
export async function getImageDetails(path, width, height, aspect) {
const loadedImage = loadImage(path);

View File

@ -42,27 +42,24 @@
"homepage": "https://github.com/RafidMuhymin/astro-imagetools#readme",
"dependencies": {
"@astropub/codecs": "0.4.4",
"@keyv/sqlite": "^4.0.5",
"@polymech/cache": "file:../../../polymech-mono/packages/cache",
"@polymech/commons": "file:../../../polymech-mono/packages/commons",
"@polymech/fs": "file:../../../polymech-mono/packages/fs",
"file-type": "17.1.1",
"file-type": "^17.1.6",
"find-cache-dir": "3.3.2",
"find-up": "^6.3.0",
"imagetools-core": "^9.1.0",
"keyv": "^5.5.0",
"keyv-file": "^5.1.3",
"object-hash": "3.0.0",
"p-map": "^7.0.3",
"p-timeout": "^6.1.4",
"potrace": "2.1.8"
"sharp": "^0.34.1"
},
"devDependencies": {
"vitest": "^3.2.4"
},
"optionalDependencies": {
"imagetools-core": "3.0.2"
},
"peerDependencies": {
"astro": ">=0.26 || >=1.0.0-beta"
}
}
}

View File

@ -8,7 +8,6 @@ export default function config() {
ssr: {
external: [
"sharp",
"potrace",
"file-type",
"object-hash",
"find-cache-dir",

View File

@ -1,13 +1,13 @@
// @ts-check
import {
builtins,
loadImage,
applyTransforms,
generateTransforms,
} from "imagetools-core";
import sharp from "sharp";
export const getLoadedImage = async (src) => {
const image = loadImage(src);
const image = sharp(src);
const { width } = await image.metadata();

View File

@ -1,21 +0,0 @@
import * as path from 'path'
import Keyv from 'keyv'
import KeyvSqlite from '@keyv/sqlite'
import { resolve } from '@polymech/commons'
export const store = (storePath, ns = 'ns-unknown', opts = {}) => {
const keyvSqlite = new KeyvSqlite(path.resolve(resolve(storePath)))
return new Keyv({ store: keyvSqlite, ttl: 5000, namespace: ns, ...opts })
}
export const get = async (key, storePath, ns = 'ns-unknown', opts = {}) => {
const keyv = store(storePath, ns, opts)
return await keyv.get(key)
}
export const set = async (key, value, storePath, ns = 'ns-unknown', opts = {}) => {
const keyv = store(storePath, ns, opts)
return await keyv.set(key, value)
}
export const list = async (key, value, storePath, ns = 'ns-unknown', opts = {}) => {
const keyv = store(storePath, ns, opts)
return await keyv.set(key, value)
}