Skip to content

Get image width and height given a file path using minimal dependencies (no need for PIL, libjpeg, libpng, etc)

License

Notifications You must be signed in to change notification settings

mseimys/image_size

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Look, Ma! No deps!

Get image width and height given a file path using minimal dependencies (no need for PIL, libjpeg, libpng, etc).

Why don't you just use PIL?

PIL is huge and has lots of dependencies, may be an overkill if you just want the dimensions. If you already have PIL installed, then sure, use it instead.

This was written in answer for the question "Get Image size WITHOUT loading image into memory" (using Python) in stackoverflow. The OP said:

@PauloScardine hey thanks Paulo, this is great! It's always so nice to have code that can be easily deployed without bringing in dependencies, and this fits the bill! As you say, avoiding PIL is worth it for its own sake.

Usage

Right now only for PNG, JPEG and GIF. Very untested, fork and send PRs.

from get_image_size import get_image_size, UnknownImageFormat

try:
    width, height = get_image_size('/path/to/image.ext')
except UnknownImageFormat:
    width, height = -1, -1

About

Get image width and height given a file path using minimal dependencies (no need for PIL, libjpeg, libpng, etc)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%