Skip to content
This repository has been archived by the owner on Oct 24, 2019. It is now read-only.

Commit

Permalink
Version 0.4.0
Browse files Browse the repository at this point in the history
Rename package to imdirect again. Its was wittier and better.
  • Loading branch information
hbldh committed Aug 31, 2016
1 parent 5a17a59 commit 76dc532
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
branch = True
source = autopil
include = */autopil/*
source = imdirect
include = */imdirect/*
omit =
*/setup.py

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ install:
- "pip install pytest-cov"
- "pip install python-coveralls"
- "pip install -e ."
script: py.test tests/ --cov autopil --cov-report term-missing
script: py.test tests/ --cov imdirect --cov-report term-missing
after_success:
- coveralls
24 changes: 12 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
autopil
imdirect
=======

|Build Status| |Coverage Status|
Expand Down Expand Up @@ -28,7 +28,7 @@ Installation

::

pip install git+https://www.github.com/hbldh/autopil
pip install git+https://www.github.com/hbldh/imdirect

Usage
-----
Expand All @@ -38,12 +38,12 @@ Demonstration of the monkey patching and how it works:
.. code:: python
from PIL import Image
import autopil
import imdirect
img = Image.open('2016-08-28 15.11.44.jpg')
print("{0}, Orientation: {1}".format(img, img._getexif().get(274)))
autopil.monkey_patch()
imdirect.monkey_patch()
img_autorotated = Image.open('2016-08-28 15.11.44.jpg')
print("{0}, Orientation: {1}".format(img_autorotated, img_autorotated._getexif().get(274)))
Expand All @@ -55,12 +55,12 @@ The output of the above:
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=3024x4032 at 0x7F44B5DF5150>, Orientation: 1
The package can also be used without monkey patching ``PIL`` and instead using the
``autopil.autopil_open`` method directly:
``imdirect.imdirect_open`` method directly:

.. code:: python
from autopil import autopil_open
img = autopil_open('2016-08-28 15.11.44.jpg')
from imdirect import imdirect_open
img = imdirect_open('2016-08-28 15.11.44.jpg')
Tests
Expand All @@ -73,7 +73,7 @@ Tests can be run with `pytest <http://doc.pytest.org/en/latest/>`_:
Testing started at 13:28 ...
============================= test session starts ==============================
platform linux2 -- Python 2.7.12, pytest-3.0.1, py-1.4.31, pluggy-0.3.1
rootdir: /home/hbldh/Repos/autopil, inifile:
rootdir: /home/hbldh/Repos/imdirect, inifile:
collected 4 items
test_autorotate.py ...
Expand All @@ -89,9 +89,9 @@ References
.. [2] Exif orientation (http://sylvana.net/jpegcrop/exif_orientation.html)
.. |Build Status| image:: https://travis-ci.org/hbldh/autopil.svg?branch=master
:target: https://travis-ci.org/hbldh/autopil
.. |Coverage Status| image:: https://coveralls.io/repos/github/hbldh/autopil/badge.svg?branch=master
:target: https://coveralls.io/github/hbldh/autopil?branch=master
.. |Build Status| image:: https://travis-ci.org/hbldh/imdirect.svg?branch=master
:target: https://travis-ci.org/hbldh/imdirect
.. |Coverage Status| image:: https://coveralls.io/repos/github/hbldh/imdirect/badge.svg?branch=master
:target: https://coveralls.io/github/hbldh/imdirect?branch=master


16 changes: 8 additions & 8 deletions autopil/__init__.py → imdirect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
autopil
imdirect
=======
PIL extension performing automatic rotation of opened JPEG images.
Expand All @@ -28,7 +28,7 @@
::
pip install git+https://www.github.com/hbldh/autopil
pip install git+https://www.github.com/hbldh/imdirect
Usage
-----
Expand All @@ -38,12 +38,12 @@
.. code:: python
from PIL import Image
import autopil
import imdirect
img = Image.open('2016-08-28 15.11.44.jpg')
print("{0}, Orientation: {1}".format(img, img._getexif().get(274)))
autopil.monkey_patch()
imdirect.monkey_patch()
img_autorotated = Image.open('2016-08-28 15.11.44.jpg')
print("{0}, Orientation: {1}".format(img_autorotated, img_autorotated._getexif().get(274)))
Expand All @@ -55,13 +55,13 @@
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=3024x4032 at 0x7F44B5DF5150>, Orientation: 1
The package can also be used without monkey patching `PIL` and instead using the
`autopil.autopil_open` method directly:
`imdirect.imdirect_open` method directly:
.. code:: python
from autopil import autopil_open
from imdirect import imdirect_open
img = autopil_open('2016-08-28 15.11.44.jpg')
img = imdirect_open('2016-08-28 15.11.44.jpg')
print("{0}, Orientation: {1}".format(img, img._getexif().get(274)))
# Output: "<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=3024x4032 at 0x7F44B5DFCE50>, Orientation: 1"
Expand All @@ -73,7 +73,7 @@


# Version information.
__version__ = '0.3.2'
__version__ = '0.4.0'
version = __version__ # backwards compatibility name
try:
version_info = [int(x) if x.isdigit() else x for x in
Expand Down
14 changes: 7 additions & 7 deletions autopil/_autorotate.py → imdirect/_autorotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import io

from PIL import Image, ExifTags
from PIL.Image import open as imopen
from PIL.Image import open as pil_open
import piexif

__all__ = [
"ImDirectException",
"autorotate",
"autopil_open",
"imdirect_open",
"monkey_patch",
"update_exif_for_rotated_image",
"save_with_exif_info"
Expand Down Expand Up @@ -146,7 +146,7 @@ def update_exif_for_rotated_image(exif):
return exif


def autopil_open(fp, mode="r"):
def imdirect_open(fp, mode="r"):
"""Opens, identifies the given image file, and rotates it if it is a JPEG.
Note that this method does NOT employ the lazy loading methodology that
Expand All @@ -162,7 +162,7 @@ def autopil_open(fp, mode="r"):
opened and identified.
"""
img = imopen(fp, mode)
img = pil_open(fp, mode)
if img.format == 'JPEG':
# Read Exif tag on image.
if isinstance(fp, string_types):
Expand All @@ -185,7 +185,7 @@ def autopil_open(fp, mode="r"):
with io.BytesIO() as bio:
img_rot.save(bio, format='jpeg', exif=piexif.dump(exif))
bio.seek(0)
img_rot_new = imopen(bio, mode)
img_rot_new = pil_open(bio, mode)
# Since we use a BytesIO we need to avoid the lazy loading of the PIL image.
# Therefore, we explicitly load the data here.
img_rot_new.load()
Expand All @@ -201,9 +201,9 @@ def monkey_patch(enabled=True):
"""
if enabled:
Image.open = autopil_open
Image.open = imdirect_open
else:
Image.open = imopen
Image.open = pil_open


def save_with_exif_info(img, *args, **kwargs):
Expand Down
19 changes: 11 additions & 8 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
from __future__ import absolute_import

from PIL import Image
import autopil
import imdirect

img = Image.open('2016-08-28 15.11.44.jpg')
image_path = 'tests/testfile_6.jpg'

img = Image.open(image_path)
print("{0}, Orientation: {1}".format(img, img._getexif().get(274)))

autopil.monkey_patch()
img_autorotated = Image.open('2016-08-28 15.11.44.jpg')
imdirect.monkey_patch()
img_autorotated = Image.open(image_path)
print("{0}, Orientation: {1}".format(img_autorotated, img_autorotated._getexif().get(274)))
imdirect.monkey_patch(False)

autopil.monkey_patch(False)

from autopil import autopil_open
img = autopil_open('2016-08-28 15.11.44.jpg')
from imdirect import imdirect_open
img = imdirect_open(image_path)
print("{0}, Orientation: {1}".format(img, img._getexif().get(274)))


6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
def read(f):
return open(f, encoding='utf-8').read()

with open('autopil/__init__.py', 'r') as fd:
with open('imdirect/__init__.py', 'r') as fd:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)


setup(
name='autopil',
name='imdirect',
version=version,
author='Henrik Blidh',
author_email='henrik.blidh@nedomkull.com',
url='https://github.com/hbldh/autopil',
url='https://github.com/hbldh/imdirect',
description='PIL extension performing automatic rotation of opened JPEG images',
long_description=read('README.rst'),
license='MIT',
Expand Down
12 changes: 6 additions & 6 deletions tests/test_autorotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os

from PIL import Image
import autopil
import imdirect

this_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -30,27 +30,27 @@ def test_autorotate_1():
assert img.height == 225
assert img._getexif().get(274) == 6

img_rot = autopil.autorotate(img)
img_rot = imdirect.autorotate(img)
assert img_rot.width == 225
assert img_rot.height == 300
assert not hasattr(img_rot, '_getexif')


def test_autopil_open_with_string_path():
def test_imdirect_open_with_string_path():
image_path = os.path.join(this_dir, 'testfile_6.jpg')

img = Image.open(image_path)
assert img.width == 300
assert img.height == 225
assert img._getexif().get(274) == 6

img_rot = autopil.autopil_open(image_path)
img_rot = imdirect.imdirect_open(image_path)
assert img_rot.width == 225
assert img_rot.height == 300
assert img_rot._getexif().get(274) == 1


def test_autopil_open_with_filelike():
def test_imdirect_open_with_filelike():
image_path = os.path.join(this_dir, 'testfile_6.jpg')
with open(image_path, 'rb') as f:
img = Image.open(f)
Expand All @@ -59,7 +59,7 @@ def test_autopil_open_with_filelike():
assert img._getexif().get(274) == 6

with open(image_path, 'rb') as f:
img_rot = autopil.autopil_open(f)
img_rot = imdirect.imdirect_open(f)
assert img_rot.width == 225
assert img_rot.height == 300
assert img_rot._getexif().get(274) == 1
8 changes: 4 additions & 4 deletions tests/test_monkey_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
import os

from PIL import Image
import autopil
import imdirect

this_dir = os.path.dirname(os.path.abspath(__file__))


def test_monkey_patching():
image_path = os.path.join(this_dir, 'testfile_6.jpg')
autopil.monkey_patch(False)
imdirect.monkey_patch(False)
img = Image.open(image_path)
assert img.width == 300
assert img.height == 225
assert img._getexif().get(274) == 6

autopil.monkey_patch(True)
imdirect.monkey_patch(True)
img = Image.open(image_path)
assert img.width == 225
assert img.height == 300
assert img._getexif().get(274) == 1

autopil.monkey_patch(False)
imdirect.monkey_patch(False)
img = Image.open(image_path)
assert img.width == 300
assert img.height == 225
Expand Down

0 comments on commit 76dc532

Please sign in to comment.