Skip to content

fisker/jpeg-buffer-orientation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jpeg-buffer-orientation

gzip size

Travis Codacy Badge Coveralls github

devDependencies Issues Issues GitHub last commit GitHub Release Date

styled with prettier MIT license

Get orientation of JPEG file.

Install

yarn add --dev jpeg-buffer-orientation

Usage

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>

demo

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)

API

getJpegOrientation(buffer)

  • buffer

    type: ArrayBuffer

  • @returns

    type: Number|undefined

FYI

this package is design for use in browser, not optimized for node.

  1. accept Buffer instead of ArrayBuffer should be easier to use.
  2. instead of reading the whole image, just reading head maybe better.