You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By clicking &ldqu
8000
o;Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
It would be really nice to be able to transform the image.
My use case: add a colorize=white|black parameter.
Idea of the transform hook I would add:
import{getImgParams}from"openimg/node";functionloader({ request }){constheaders=newHeaders();headers.set('Cache-Control','public, max-age=31536000, immutable');returngetImgResponse(request,{
headers,getImgParams: ({ request })=>{constdefaultParams=getImgParams({ request });constcolorize=url.searchParams.get('colorize')||undefined;if(colorize&&!['white','black'].includes(colorize)){returnnewResponse(null,{status: 400,statusText: 'Search param "colorize" must be either "white" or "black" or unset',});}return{
...defaultParams,
colorize,};},transform: async({ params, pipeline })=>{constinfoPromise=newPromise((resolve)=>{pipeline.on('info',(info)=>{resolve(info);});});constoutputImgInfo=awaitinfoPromise;// This could also be passed as function's parameter with `params, pipeline`.if(params.colorize){if(!['png','svg'].includes(outputImgInfo.format)){returnnewResponse(null,{status: 400,statusText: 'Colorize is only supported for PNG and SVG images',});}if(outputImgInfo.format==='svg'){// Convert SVG to PNG before colorizingpipeline.png();}switch(params.colorize){case'white':
pipeline.grayscale().modulate({brightness: 100,saturation: 0,});break;case'black':
pipeline.grayscale().modulate({brightness: 0,saturation: 0,});break;default:
returnnewResponse(null,{status: 400,statusText: 'Unhandled colorize value',});}}returnpipeline;},});}
The text was updated successfully, but these errors were encountered:
Thanks a ton for brining this up and opening a PR as well. I had to make a few changes for the custom cacheKey logic and just went ahead and did it myself (as discussed in your PR).
Transform hook now released as getSharpPipeline in v1.0.0. 🥳
Would love if you give it a spin, @davidesigner! I also exposed a new params property in the React component to make it easier to send custom search parameters as part of the image source to the optimizer endpoint.
Uh oh!
There was an error while loading. Please reload this page.
It would be really nice to be able to transform the image.
My use case: add a
colorize=white|black
parameter.Idea of the
transform
hook I would add:The text was updated successfully, but these errors were encountered: