Skip to content

Commit

Permalink
options(): convert() now takes StickerOptions as it's 2nd param
Browse files Browse the repository at this point in the history
  • Loading branch information
AlenVelocity committed Nov 12, 2021
1 parent 059e9d3 commit c9f5796
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/Sticker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,17 @@ export class Sticker {

/**
* Builds the sticker
* @param {string} [type] - How you want your sticker to look like
* @returns {Promise<Buffer>} A promise that resolves to the sticker buffer
* @example
* const sticker = new Sticker('./image.png')
* const buffer = sticker.build()
*/
public build = async (
type: StickerTypes = (this.metadata.type as StickerTypes) || StickerTypes.DEFAULT
): Promise<Buffer> => {
const buffer = await this._parse()
const mime = await this._getMimeType(buffer)
const { quality, background } = this.metadata
return new Exif(this.metadata as IStickerConfig).add(
await convert(buffer, mime, type, {
quality,
background
})
await convert(buffer, mime, this.metadata)
)
}

Expand Down
13 changes: 5 additions & 8 deletions src/internal/convert.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import sharp, { Color } from 'sharp'
import sharp from 'sharp'
import videoToGif from './videoToGif'
import { writeFile } from 'fs-extra'
import { tmpdir } from 'os'
import crop from './crop'
import { StickerTypes } from './Metadata/StickerTypes'
import { defaultBg } from '../Utils'
import { IStickerOptions } from '..'

const convert = async (
data: Buffer,
mime: string,
type: StickerTypes = StickerTypes.DEFAULT,
{
quality = 100,
background = defaultBg
}: {
quality?: number
background?: Color
}
): Promise<Buffer> => {
background = defaultBg,
type = StickerTypes.DEFAULT,
}: IStickerOptions): Promise<Buffer> => {
const isVideo = mime.startsWith('video')
let image = isVideo ? await videoToGif(data) : data
const isAnimated = isVideo || mime.includes('gif')
Expand Down

0 comments on commit c9f5796

Please sign in to comment.