Skip to content

Commit

Permalink
return content_type as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Adams committed Feb 18, 2013
1 parent fefd0c7 commit 3da8168
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.txt
Expand Up @@ -19,23 +19,29 @@ For a single image:
src/sample.png
width: 405
height: 239
content_type: image/png

Wildcards also work (escape \* in markdown for PyPi RST...):

> dimensions src/\*.png
src/sample.png
width: 405
height: 239
content_type: image/png
src/sample2.png
width: 473
height: 469
content_type: image/png

As always, full details are available via `dimensions -h`.

In Python code, simply
In Python code, simply call `dimensions.dimensions`. If you provide a
sequence of filenames, you get back a sequence of tuples; if you provide
just a single filename, you get back a single tuple.

import dimensions
dims = dimensions.dimensions('./src/sample.png')
# (405, 239, 'image/png', './src/sample.png')

future
------
Expand Down
1 change: 1 addition & 0 deletions dimensions/GIFFile.py
Expand Up @@ -30,6 +30,7 @@ def _load(self):
# TODO: raise appropriate exception
print('%s is not GIF signature' % magic)
exit()
self.content_type = 'image/gif'
hw = struct.Struct('h')
x = hw.unpack(self.fp.read(2))[0]
y = hw.unpack(self.fp.read(2))[0]
Expand Down
1 change: 1 addition & 0 deletions dimensions/PNGFile.py
Expand Up @@ -46,6 +46,7 @@ def _load(self):
# TODO: raise appropriate exception
print('%s is not PNG signature' % magic)
exit()
self.content_type = 'image/png'

# parse chunk stream
l, t, c = Chunk._length, Chunk._type, Chunk._crc
Expand Down
6 changes: 3 additions & 3 deletions dimensions/core.py
Expand Up @@ -34,7 +34,7 @@ def get_dimensions(filenames):
raise NotImplementedError

x, y = img.size
dims.append((x, y, filename))
dims.append((x, y, img.content_type, filename))
return dims


Expand Down Expand Up @@ -72,8 +72,8 @@ def cli():
logging.basicConfig(level=log_level)

dims = get_dimensions(args.filenames)
for x, y, filename in dims:
print('%s\n width: %d\n height: %d' % (filename, x, y))
for x, y, content_type, filename in dims:
print('%s\n width: %d\n height: %d\n content_type: %s' % (filename, x, y, content_type))

if '__main__' == __name__:
dimensions()

0 comments on commit 3da8168

Please sign in to comment.