File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -4,34 +4,36 @@ import sharp from 'sharp';
44
55export interface IOutput {
66 encoded : string ;
7- decoded : Uint8ClampedArray ;
87 width : number ;
98 height : number ;
109}
1110
12- export const blurhashFromURL = async ( url : string ) => {
11+ export const blurhashFromURL = async ( url : string , { size = 32 } : { size ?: number } = { } ) => {
12+
1313 const response = await fetch ( url ) ;
1414 const arrayBuffer = await response . arrayBuffer ( ) ;
1515 const returnedBuffer = Buffer . from ( arrayBuffer ) ;
1616
1717 const { data, info } = await sharp ( returnedBuffer )
18+ . resize ( size , size , {
19+ fit : "inside" ,
20+ } )
1821 . ensureAlpha ( )
1922 . raw ( )
2023 . toBuffer ( {
2124 resolveWithObject : true ,
2225 } ) ;
26+
2327 const encoded = encode (
2428 new Uint8ClampedArray ( data ) ,
2529 info . width ,
2630 info . height ,
2731 4 ,
2832 4
2933 ) ;
30- const decoded = decode ( encoded , info . width , info . height ) ;
3134
3235 const output : IOutput = {
3336 encoded : encoded ,
34- decoded : decoded ,
3537 width : info . width ,
3638 height : info . height ,
3739 } ;
Original file line number Diff line number Diff line change 11const { blurhashFromURL } = require ( "../dist/index.js" ) ;
22
33async function getBlurhash ( ) {
4- const output = await blurhashFromURL ( "https://i.imgur.com/NhfEdg2.png" ) ;
4+ const output = await blurhashFromURL ( "https://i.imgur.com/NhfEdg2.png" , {
5+ size : 32 ,
6+ } ) ;
57 console . log ( output ) ;
68}
79
You can’t perform that action at this time.
0 commit comments