Is there an exif library out there for Python 3.x? It seems every exif library I run into is for Python 2.x only. I don't need anything too fancy. Just reading the values is enough.
Option 1. Use pyexiv2. See: pyexiv2 Bug #824440: Python 3 support You need boost-python for py3k and also to manually apply the patch posted at the end of the bug above, but aside from that it works. Probably easiest to get up and running under latest Ubuntu.
Option 2. Use PIL Downside: this branch/fork doesn't seem to be actively developed.
from PIL import Image
from PIL.ExifTags import TAGS
image = Image.open("test.jpg")
exif = image._getexif()
# decode exif using TAGS
Option 3. Use PythonMagick
from PythonMagick import Image
img = Image("image.jpg")
print img.attribute("EXIF:Orientation")
See also: Exif manipulation library for python
For reference, the pyexiv2 homepage now has a deprecation warning which points to Gexiv2, a GObject-introspection based wrapper around libexiv2 (the same library pyexiv2 wraps) specifically for the purpose of Python 3.x support.
Unfortunately, at the time of writing, installation of Gexiv2 is still painful and thus far I've been unable to get it working on Ubuntu Precise (looks like the libs are out of date - probably serves me right for sticking around on an LTS...), so PIL is still the best option for reading EXIF tags in Python 3.
Related
I want to use one of the newest versions of Python, (3.5+), and I need to import Image. I use:
from PIL import Image
except this returns an error. I don't have the error on my right now but the important part is there is a problem with PIL (I have already determined that from my Python Discord server)
Can I use pillow? I think I have that installed. I would try it but I want to know how (and if) it's applicable. Thanks
Can I use pillow?
Sure. pillow is a successor project of PIL, as development on the latter was last continued in 2011.
The first thing mentioned in the official pillow documentation is how to import the Image class.
I tried to use Python's Image Module on my Mac (new to mac)and I had trouble setting it up. I have Yosemite and some of the posts that I found online didn't work. I ended up installing Homebrew and I finally got PIL on my computer. However, instead of using import image (which I saw people doing it online), I have to use from PIL import image. Is there key difference between import Image and from PIL import Image. It's the first time that I actually use Image module.
One more question, do I actually need to install third party tools like Homebrew and Macports to set up my environment?
If you are using PIL, you might be able to use import Image.
If you are using Pillow, you must use from PIL import Image.
This is by design.
1-Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
2-Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead. so be careful with it
3-Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.
In python, modules are represented by *.py files. These files can be imported using import module. That statement will first search for a build-in module, if it fails to find one it will search in a given list of directories (PYTHONPATH).
When you imported your module, you can then access names (aka functions or classes) via module.name.
However, when using from module import myFunc you can reference that function directly without using the modulename. The same goes for from module import *.
Now, to the PIL:
Image is a name (here class) in the PIL module. As, import Image searches for modules called Image. It can't find one, because Image is part of the PIL module.
You can also look at the documentation here: Modules in Python
I hope this helped you understanding modules better.
for my facebook app, I am trying to generate image from the data. So, I need to put the text and some images on another background image . I thought of using PIL, but it had lot of dependencies which are making me mad. Also, at the end I have to do all these installations on heroku also . So, anyway simple way to add text and image to another image in python#Django ?
Some of the problems using pil : when using font feature, getting this error : The _imagingft C module is not installed
I installed pillow also .
You will need some form of an image processing library. Even some components of Django, like ImageField, need PIL.
If you are having problems building PIL, there is a fork called Pillow, which supposedly aims to package it up better to make installation easier.
I'm building my first Python program :) However, I installed Python 3.2 instead of 2.7, as the newer version has TkInter included. Now I can't find a way to use PIL in it.
I have read this question but as a total newcomer it's not much help for me. I installed zlib and the libjpeg but couldn't get any further when it comes to building the pil-py3k. I have no idea what I am supposed to do in here:
# --------------------------------------------------------------------
# Library pointers.
#
# Use None to look for the libraries in well-known library locations.
# Use a string to specify a single directory, for both the library and
# the include files. Use a tuple to specify separate directories:
# (libpath, includepath). Examples:
#
# JPEG_ROOT = "/home/libraries/jpeg-6b"
# TIFF_ROOT = "/opt/tiff/lib", "/opt/tiff/include"
#
# If you have "lib" and "include" directories under a common parent,
# you can use the "libinclude" helper:
#
# TIFF_ROOT = libinclude("/opt/tiff")
FREETYPE_ROOT = None
JPEG_ROOT = None
TIFF_ROOT = None
ZLIB_ROOT = None
TCL_ROOT = None
Is there an easier way to enable PIL with PNG and JPEG support for Python 3?
One option is to download an older version of Python but then there won't be TkInter?
I wish you understand I'm a newcomer so please forgive me if I make any stupid questions. Python seems really cool! ;) Any help is appreciated.
Unofficial PIL for Python 3.2 is the answer
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Just found out that there is PIL fork Pillow: https://pypi.python.org/pypi/Pillow/2.1.0
As agf mentioned in his comment on your question, tkinter has been included with every version of Python for years. The important difference is a restructuring of the tkinter packages. The biggest of those changes is the base package name: In Python 3.x, the tkinter package is named tkinter, while in Python 2.x, the package is named Tkinter (note the capital "T"). You can see the Python 2.7.2 docs on tkinter for more information.
Unfortunately, I haven't used PIL with Python 3.x, so I can't be of any assistance there, but hopefully you can accomplish what you need in 2.7 instead.
See http://mail.python.org/pipermail/image-sig/2012-October/007080.html for an updated port that works on Python 2+3
What is python-3 using instead of PIL for manipulating Images?
The "friendly PIL fork" Pillow works on Python 2 and 3. Check out the Github project for support matrix and so on.
Christoph Gohlke managed to build PIL (for Windows only) for python versions up to 3.3: http://www.lfd.uci.edu/~gohlke/pythonlibs/
I tried his version of PIL with Python 3.2, and image open/create/pixel manipulation/save all work.
Qt works very well with graphics. In my opinion it is more versatile than PIL.
You get all the features you want for graphics manipulation, but there's also vector graphics and even support for real printers. And all of that in one uniform API, QPainter.
To use Qt you need a Python binding for it: PySide or PyQt4.
They both support Python 3.
Here is a simple example that loads a JPG image, draws an antialiased circle of radius 10 at coordinates (20, 20) with the color of the pixel that was at those coordinates and saves the modified image as a PNG file:
from PySide.QtCore import *
from PySide.QtGui import *
app = QCoreApplication([])
img = QImage('input.jpg')
g = QPainter(img)
g.setRenderHint(QPainter.Antialiasing)
g.setBrush(QColor(img.pixel(20, 20)))
g.drawEllipse(QPoint(20, 20), 10, 10)
g.end()
img.save('output.png')
But please note that this solution is quite 'heavyweight', because Qt is a large framework for making GUI applications.
As of March 30, 2012, I have tried and failed to get the sloonz fork on GitHub to open images. I got it to compile ok, but it didn't actually work. I also tried building gohlke's library, and it compiled also but failed to open any images. Someone mentioned PythonMagick above, but it only compiles on Windows. See PythonMagick on the wxPython wiki.
PIL was last updated in 2009, and while it's website says they are working on a Python 3 port, it's been 3 years, and the mailing list has gone cold.
To solve my Python 3 image manipulation problem, I am using subprocess.call() to execute ImageMagick shell commands. This method works.
See the subprocess module documentation.
You can use my package mahotas on Python 3. It is numpy-based rather than PIL based.
You want the Pillow library, here is how to install it on Python 3:
pip3 install Pillow
If that does not work for you (it should), try normal pip:
pip install Pillow
Depending on what is needed, scikit-image may be the best choice, with manipulations going way beyond PIL and the current version of Pillow. Very well-maintained, at least as much as Pillow. Also, the underlying data structures are from Numpy and Scipy, which makes its code incredibly interoperable. Examples that pillow can't handle:
You can see its power in the gallery. This paper provides a great intro to it. Good luck!
If you are on Python3 you can also use the library PILasOPENCV which works in Python 2 and 3. Function api calls are the same as in PIL or pillow but internally it works with OpenCV and numpy to load, save and manipulate images. Have a look at https://github.com/bunkahle/PILasOPENCV or install it with pip install PILasOPENCV. Not all PIL functions have been simulated but the most common functions work.