Get orientation of JPEG file.
yarn add --dev jpeg-buffer-orientation
in browser
<script type="module">
import getOrientation from 'https://unpkg.com/jpeg-buffer-orientation?module'
const response = await fetch('./foo.jpg')
const buffer = await response.arrayBuffer()
const orientation = getOrientation(buffer)
console.log('orientation', orientation)
</script>
in browser (legacy)
<script src="https://unpkg.com/jpeg-buffer-orientation"></script>
<script>
const buffer = myJpegFile.arrayBuffer()
console.log(getOrientation(buffer))
</script>
in node (not recommended)
import fs from 'node:fs/promises'
import getOrientation from 'jpeg-buffer-orientation'
const myJpegFile = new URL('./foo.jpg', import.meta.url)
const {buffer} = await fs.readFile(myJpegFile)
const orientation = getOrientation(buffer)
console.log('orientation', orientation)
getJpegOrientation(buffer)
-
buffer
type:
ArrayBuffer
-
@returns
type:
Number|undefined
this package is design for use in browser, not optimized for node.
- accept
Buffer
instead ofArrayBuffer
should be easier to use. - instead of reading the whole image, just reading head maybe better.