Skip to content

Commit

Permalink
feat(matrix): support browser image-size
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 9, 2023
1 parent 9e43009 commit e504c3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion adapters/matrix/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "@satorijs/adapter-matrix",
"description": "Matrix Adapter for Satorijs",
"version": "0.0.1",
"version": "3.1.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
"lib"
],
"browser": {
"image-size": false
},
"author": "Anillc <[email protected]>",
"license": "MIT",
"repository": {
Expand Down
17 changes: 16 additions & 1 deletion adapters/matrix/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import imageSize from 'image-size'
import { Dict } from '@satorijs/satori'
import { Dict, pick } from '@satorijs/satori'
import { MatrixBot } from './bot'

export interface Size {
width: number
height: number
}

export function getImageSize(buffer: ArrayBuffer): Size {
if (typeof Buffer !== 'undefined') {
return imageSize(Buffer.from(buffer))
}
const blob = new Blob([buffer])
const image = new Image()
image.src = URL.createObjectURL(blob)
return pick(image, ['width', 'height'])
}

export interface Transaction {
txnId: string
events: ClientEvent[]
Expand Down

0 comments on commit e504c3b

Please sign in to comment.