From bfb405e27e5ccd3cfbe73413b010c8cc37a3e5d8 Mon Sep 17 00:00:00 2001 From: jiblett1000 Date: Thu, 9 Mar 2023 23:43:46 -0800 Subject: [PATCH] strapi local image sharp provider --- src/provider.ts | 1 + src/runtime/providers/strapisharp.ts | 42 ++++++++++++++++++++++++++++ src/types/module.ts | 1 + 3 files changed, 44 insertions(+) create mode 100644 src/runtime/providers/strapisharp.ts diff --git a/src/provider.ts b/src/provider.ts index b697d876a..745b26002 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -26,6 +26,7 @@ const BuiltInProviders = [ 'sanity', 'twicpics', 'strapi', + 'strapisharp', 'storyblok', 'unsplash', 'vercel', diff --git a/src/runtime/providers/strapisharp.ts b/src/runtime/providers/strapisharp.ts new file mode 100644 index 000000000..2ccabaefe --- /dev/null +++ b/src/runtime/providers/strapisharp.ts @@ -0,0 +1,42 @@ +import { joinURL } from 'ufo' +import type { ProviderGetImage } from '../../types' +import { createOperationsGenerator } from '#image' + +// https://strapi-community.github.io/strapi-plugin-local-image-sharp/ + +const operationsGenerator = createOperationsGenerator({ + keyMap: { + width: 'width', + height: 'height', + resize: 'resize', + fit: 'fit', + position: 'positon', + trim: 'trim', + format: 'format', + quality: 'quality', + rotate: 'rotate', + enlarge: 'enlarge', + flip: 'flip', + flop: 'flop', + sharpen: 'sharpen', + median: 'median', + gamma: 'gamma', + negate: 'negate', + normalize: 'normalize', + threshold: 'threshold', + grayscale: 'grayscale', + animated: 'animated' + }, + joinWith: ',', + formatter: (key, value) => `${key}_${value}` +}) + +export const getImage: ProviderGetImage = (src, { modifiers, baseURL = 'http://localhost:1337/uploads' } = {}) => { + const operations = operationsGenerator(modifiers as any) + + return { + url: joinURL(baseURL, operations, src) + } +} + +export const validateDomains = true diff --git a/src/types/module.ts b/src/types/module.ts index d38a538fa..e13d51dd2 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -57,6 +57,7 @@ export interface ImageProviders { twicpics?: any storyblok?: any, strapi?: any, + strapisharp?: any, imageengine?: any, ipx?: Partial static?: Partial