Skip to content

Commit

Permalink
fix: changed the image-size usage to handle uint8array
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Feb 8, 2024
1 parent 308bad7 commit 1a0e080
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/ssi-sdk-core/src/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type SizeCalculationResult = {
}

export const getImageMediaType = async (base64: string): Promise<string | undefined> => {
const buffer: Buffer = Buffer.from(base64, 'base64')
const result: SizeCalculationResult = imageSize(buffer)
const int8Array: Uint8Array = base64ToUint8Array(base64)
const result: SizeCalculationResult = imageSize(int8Array)

switch (result.type) {
case undefined:
Expand Down Expand Up @@ -48,3 +48,9 @@ export const downloadImage = async (url: string): Promise<IImageResource> => {
contentType: contentType || undefined,
}
}

const base64ToUint8Array = (base64: string): Uint8Array => {
const base64WithoutPrefix: string = base64.split(',').pop()!;
const buffer = Buffer.from(base64WithoutPrefix, 'base64');
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}

0 comments on commit 1a0e080

Please sign in to comment.