Skip to content

Commit

Permalink
fix: changed image-size library version to a react friendly one
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Feb 8, 2024
1 parent 1aa7c3d commit 308bad7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/ssi-sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@veramo/core": "4.2.0",
"cross-fetch": "^3.1.8",
"debug": "^4.3.4",
"image-size": "^1.0.2",
"image-size": "^2.0.0-beta.2",
"uint8arrays": "3.1.1"
},
"devDependencies": {
Expand Down
14 changes: 10 additions & 4 deletions packages/ssi-sdk-core/src/utils/image.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import fetch from 'cross-fetch'
import sizeOf from 'image-size'
import { ISizeCalculationResult } from 'image-size/dist/types/interface'
import {imageSize} from 'image-size'
import { IImageDimensions, IImageResource } from '../types'

type SizeCalculationResult = {
width: number | undefined
height: number | undefined
orientation?: number
type?: string
}

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

switch (result.type) {
case undefined:
Expand All @@ -19,7 +25,7 @@ export const getImageMediaType = async (base64: string): Promise<string | undefi

export const getImageDimensions = async (base64: string): Promise<IImageDimensions> => {
const buffer: Buffer = Buffer.from(base64, 'base64')
const dimensions: ISizeCalculationResult = sizeOf(buffer)
const dimensions: SizeCalculationResult = imageSize(buffer)

if (!dimensions.width || !dimensions.height) {
return Promise.reject(Error('Unable to get image dimensions'))
Expand Down
11 changes: 9 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 308bad7

Please sign in to comment.