Previous Up Next
Using PEL in applications PHP Exif Library

Frequently Asked Questions (FAQ)

Quick answers to common questions

Table of Contents

What does PEL stand for?

PEL is an acronym for "PHP Exif Library". Sound simple enough, doesn't it?

But did you realise that PEL is an acronym consisting of two acronyms, one of which is recursive! So "PEL" actually stands for "PHP Hypertext Preprocessor Exchangeable image file format Library". Pyh!

What's the business with EXIF vs. Exif?

Well, since Exif is an acronym for "Exchangeable image file format" and thus you would expect it to be spelled "EXIF", just like "JPEG" which is an acronym for Joint Photographic Experts Group.

But the Exif standards spell Exif as "Exif" and so does PEL, at least since version 0.9. But should they ever decide to update their acronym to "EXIF" then PEL will revert... Luckily it does not affect the acronym PEL itself :-)

Why does PEL require PHP version 5?

The support for object-oriented programming was completely overhauled with the introduction of PHP 5 in July 2004. The changes included both semantic changes and syntaxtical changes to the PHP language.

The semantic change was the use of object references per default. This change means that when you do

  1. $object_a $ifd->getEntry(PelTag::IMAGE_DESCRIPTION);
  2. $object_a->setValue('This is my new description.');
  3. $object_b $ifd->getEntry(PelTag::IMAGE_DESCRIPTION);

then $object_a and $object_b will both reference the same element. In particular, you will see that $object_b->getValue() returns the string just stored in $object_a (since they are the same object). With PHP 4 you would have gotten two different objects, which is generally not what you want.

The syntaxtical changes from PHP 5 to PHP 4 include the addition of access modifiers to object fields (the private, protected, and public keywords), object constants, constructors named __construct(), interfaces and abstract classes, and exceptions. PEL uses all these new features to the fullest, which means that PHP 4 doesn't understand the code.

If your provider is still using PHP 4, then you should ask them to upgrade. PHP 5 has been declared stable since July 2004 and all major PHP applications (WordPress, Gallery, PhpWiki, phpMyAdmin, etc...), have been upgraded to work with PHP 5, so an upgrade should not bring you any problems, just more features and better performance.

Why do I get fatal errors from PHP?

If you get a fatal error when trying to use PEL, then your installation of PHP might be too old. PEL requires PHP version 5. Please see the question "Why does PEL require PHP version 5?" for more information.

What does "Call to a member function f() on a non-object" (where f() is getTiff() or setValue()) mean?

This is the error PHP gives when you call a method on a variable which is not an object.

PEL uses objects to represent the entire structure of a JPEG image, and many of the methods defined on those objects return other objects. In particular, the method PelJpeg::getExif() returns a PelExif object and PelIfd::getEntry() returns a PelEntry object.

But both methods can return null if no such section or entry exist. The correct way to use them is thus something along the lines of:

  1. $exif $jpeg->getExif();
  2. if ($exif != null{
  3.   $tiff $exif->getTiff();
  4.   /* Do something with the TIFF data. */
  5. else {
  6.   /* Sorry --- no Exif data found. */
  7. }

The same principle applies to the return values of PelIfd::getEntry() and all other methods which return objects.

Does PEL handle IPTC entries?

No, PEL only deals with Exif data, and no such extension is planned. Try taking at look at the PHP JPEG Metadata Toolkit which should handle IPTC along with a huge number of other metadata formats.

Why does Gettext not work?

PEL uses Gettext for localization, and thus your system must fulfill a few requirements:

  1. PHP must have support for the Gettext extension. Most installations of PHP already has this, but please double-check with phpinfo() before asking for help on the mailinglist.

  2. The system must be setup to generate locales for the languages into which PEL has been translated. Again, most commercial webhosts would have their systems configured to deal with all locales, but if you're installing PEL on your own server you'll probably have to reconfigure it.

    How to configure the locales differ from system to system. With the Debian GNU/Linux distribution you should run

    dpkg-reconfigure locales

    and then select all locales that you want your system to support.

    Restart your webserver after changing the locale setup to make the changes effective.

How to deal with broken images?

By default PEL will try to load as much from an image as possible and continue dispite any errors found. The Exif standard mandates certain formats and lengths for some entries, and sometimes these requirements are violated.

The strictness of PEL is controlled by the the method Pel::setStrictParsing(). The default is non-strict parsing. In this mode, PEL will not throw exceptions for parse errors but instead store them for later inspection via the Pel::getExceptions() method.

With an argument of true to Pel::setStrictParsing() you make PEL throw exceptions upon parse errors.

This may all sound very complex, but it is actually fairly simple for most uses: have PEL load your images in non-strict mode and check for errors afterwards, if necessary.

Please note that even if PEL is in non-strict mode it might throw exceptions while parsing an image, for example if the image cannot be recognized a JPEG or TIFF image. So it is always necessary to wrap calls to PEL in a try-catch block.

Can I use PEL for a commercial application?

Yes, no problem as long as you do not distribute your application under another license than the GNU GPL.

As you should know, PEL is licensed to you under the conditions of the GNU GPL. The license deals only with the distribution of PEL and any derivative works based on PEL, the license has nothing to say over how you may use PEL.

So if you do not distribute your code, then you can use it for whatever you want, including writing a website (commercial or not) that integrates PEL. Please see this question in the GPL FAQ.

My question is not answered here!

Please ask your questions on the PEL Development List. If an answer is found, then the FAQ will be updated.

Previous Up Next
Using PEL in applications PHP Exif Library

Documentation generated on Thu, 05 May 2011 07:18:55 +0200 by phpDocumentor 1.4.3