Last active
June 20, 2024 07:39
-
-
Save nguyenvanhoangnhan/8ad7cbd4d1a7c3e39cbf28fc44fd84df to your computer and use it in GitHub Desktop.
heic to jpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sharp from "sharp" | |
import decodeHeic from 'heic-decode' | |
import fs from 'fs' | |
export async function ConvertHeicBufferToJpegBuffer( | |
heicBuffer: Buffer, | |
): Promise<Buffer> { | |
const decodedHeic = await decodeHeic({ | |
buffer: heicBuffer, | |
}); | |
const jpegSharp = sharp(decodedHeic.data, { | |
raw: { | |
width: decodedHeic.width, | |
height: decodedHeic.height, | |
channels: 4, | |
}, | |
}).jpeg(); | |
const jpegBuffer = await jpegSharp.toBuffer(); | |
return jpegBuffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment