Skip to content

Commit

Permalink
Forgot to change the animated flag
Browse files Browse the repository at this point in the history
Additionally, I have changed the hard-coded strings to use the Types enum, for consistency throughout.
  • Loading branch information
Helvio88 committed Jan 25, 2023
1 parent 2744bc4 commit 0669f62
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/internal/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,42 @@ const convert = async (
let image = isVideo ? await videoToGif(data) : data
const isAnimated = isVideo || mime.includes('gif')

if (isAnimated && ['crop', 'circle'].includes(type)) {
if (isAnimated && [StickerTypes.CROPPED, StickerTypes.CIRCLE].includes(type)) {
const filename = `${tmpdir()}/${Math.random().toString(36)}.webp`
await writeFile(filename, image)
;[image, type] = [await crop(filename), type === 'circle' ? StickerTypes.CIRCLE : StickerTypes.DEFAULT]
;[image, type] = [await crop(filename), type === StickerTypes.CIRCLE ? StickerTypes.CIRCLE : StickerTypes.DEFAULT]
}

const img = sharp(image, { animated: type !== 'circle' }).toFormat('webp')
const img = sharp(image, { animated: isAnimated }).toFormat('webp')

switch (type) {
case StickerTypes.CROPPED:
img.resize(512, 512, {
fit: fit.cover
})
break

if (type === 'crop')
img.resize(512, 512, {
fit: fit.cover
})

if (type === 'full')
img.resize(512, 512, {
fit: fit.contain,
background
})
case StickerTypes.FULL:
img.resize(512, 512, {
fit: fit.contain,
background
})
break

if (type === 'circle') {
img.resize(512, 512, {
fit: fit.cover
}).composite([
{
input: Buffer.from(
`<svg><circle cx="256" cy="256" r="256" fill="${background}"/></svg>`
),
blend: 'dest-in',
gravity: 'northeast',
tile: true
}
])
case StickerTypes.CIRCLE:
img.resize(512, 512, {
fit: fit.cover
}).composite([
{
input: Buffer.from(
`<svg><circle cx="256" cy="256" r="256" fill="${background}"/></svg>`
),
blend: 'dest-in',
gravity: 'northeast',
tile: true
}
])
break
}

return await img
Expand Down

0 comments on commit 0669f62

Please sign in to comment.