Skip to content

Commit

Permalink
Prepare first 2.9.1-alpha.1 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaillard committed Aug 9, 2016
1 parent cb32625 commit d651b25
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 88 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ module.exports = function(grunt) {

options: {
bin : 'vendor/bin/phpunit',
configuration : 'phpunit.xml.dist',
group : 'ImageMetadataReader.Dotnet256x256AlphaPaletteTest'
configuration : 'phpunit.xml.dist'//,
//group : 'ImageMetadataReader.FujiFilmFinePixS1ProTest'
}

}, /* PHPUnit Task */
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ Metadata metadata = ImageMetadataReader.readMetadata(imagePath);

## Installation

The easiest way to install the library is to use [composer](https://getcomposer.org/ "composer") and define the
following dependency inside your `composer.json` file :

```json
{
"require": {
"gomoob/php-metadata-extractor": "~2.9"
}
}
```

Please also note that because the library is a wrapper around a Java library the `java` executable must be available
in your `PATH` variable.

## Versioning

To easier version identification the version of `php-metadata-extractor` will always be aligned with the version
of the Java `metadata-extractor`.

Stable versions of `php-metadata-extrator` will be equal to `X.Y.Z-N` where `N` represents a patch number
associated to `php-metadata-extractor`.

Unstable or uncomplete versions of `php-metadata-extractor` will be equal to `X.Y.Z-alpha.N` or
`X.Y.Z-beta.N`.

## About Gomoob

At [Gomoob](https://www.gomoob.com "Gomoob") we build high quality software with awesome Open Source frameworks
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "gomoob/php-metadata-extractor",
"description" : "PHP wrapper to easily call the Java metadata-extrator library.",
"version" : "1.0.0",
"version" : "2.9.1-alpha.1",
"license" : "MIT",
"type" : "library",
"keywords" : [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gomoob-php-metadata-extractor",
"version": "1.0.0",
"version": "2.9.1-alpha.1",
"license": "MIT",
"repository" : {
"type" : "git",
Expand Down
108 changes: 99 additions & 9 deletions src/main/php/Gomoob/MetadataExtractor/Imaging/ImageMetadataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

/**
* gomoob/php-metadata-extractor
*
* @copyright Copyright (c) 2016, GOMOOB SARL (http://gomoob.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE.md file)
*/
*
* @copyright Copyright (c) 2016, GOMOOB SARL (http://gomoob.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE.md file)
*/
namespace Gomoob\MetadataExtractor\Imaging;

use Gomoob\BinaryDriver\MetadataExtractorDriver;
Expand All @@ -32,6 +32,7 @@
use Gomoob\MetadataExtractor\Metadata\Exif\GpsDirectory;
use Gomoob\MetadataExtractor\Lang\Rational;
use Gomoob\MetadataExtractor\Metadata\Png\PngDirectory;
use Gomoob\MetadataExtractor\Metadata\Gif\GifHeaderDirectory;

/**
* Reads metadata from any supported file format.
Expand Down Expand Up @@ -60,26 +61,45 @@
*/
class ImageMetadataReader
{
/**
* The last console output, this property is only defined for the PHP version of the library. The PHP version of
* the library parses the console output of the Java `metadata-extractor` library, ths variable contains the last
* console output.
*
* @var string
*/
private static $lastOutput;

/**
* The {@link MetadataExtractorDriver} driver used to manage calls to the `metadata-extractor` library.
*
* @var \Gomoob\MetadataExtractor\Driver\MetadataExtractorDriver
*/
private $metadataExtractorDriver;

/**
* Gets the last console output.
*
* @return string the last console output.
*/
public static function getLastOutput()
{
return static::$lastOutput;
}

public static function readMetadata($file)
{
$metadata = new Metadata();

$metadataExtractorDriver = MetadataExtractorDriver::create();
$output = $metadataExtractorDriver->command(
static::$lastOutput = $metadataExtractorDriver->command(
[
$file
]
);

// Parse each line of the output
foreach (explode(PHP_EOL, $output) as $line) {
foreach (explode(PHP_EOL, static::$lastOutput) as $line) {
$trimedLine = trim($line);

// We ignore empty lines, metadata-extractor outputs empty line to have a human readable console output but
Expand Down Expand Up @@ -438,6 +458,30 @@ private static function addTagToDirectory(Directory $directory, $tagLine)
default:
// TODO: Error
}
} elseif ($directory instanceof GifHeaderDirectory) {
switch ($nameAndDescription[0]) {
case 'GIF Format Version':
break;
case 'Image Height':
$directory->setInt(GifHeaderDirectory::TAG_IMAGE_HEIGHT, intval($nameAndDescription[1]));
break;
case 'Image Width':
$directory->setInt(GifHeaderDirectory::TAG_IMAGE_WIDTH, intval($nameAndDescription[1]));
break;
case 'Color Table Size':
break;
case 'Is Color Table Sorted':
break;
case 'Bits per Pixel':
break;
case 'Has Global Color Table':
break;
case 'Background Color Index':
break;
case 'Pixel Aspect Ratio':
break;
default:
}
} elseif ($directory instanceof JfifDirectory) {
switch ($nameAndDescription[0]) {
case 'Version':
Expand Down Expand Up @@ -533,9 +577,52 @@ private static function addTagToDirectory(Directory $directory, $tagLine)
// TODO: Exception
}
} elseif ($directory instanceof PngDirectory) {
// var_dump($tagLine);
// var_dump($nameAndDescription[0]);
// var_dump($nameAndDescription[1]);
// var_dump($tagLine);
// var_dump($nameAndDescription);
switch ($nameAndDescription[0]) {
case 'Image Height':
$directory->setInt(PngDirectory::TAG_IMAGE_HEIGHT, intval($nameAndDescription[1]));
break;
case 'Image Width':
$directory->setInt(PngDirectory::TAG_IMAGE_WIDTH, intval($nameAndDescription[1]));
break;
case 'Bits Per Sample':
break;
case 'Color Type':
break;
case 'Compression Type':
break;
case 'Filter Method':
break;
case 'Interlace Method':
break;
case 'Palette Size':
break;
case 'Palette Has Transparency':
break;
case 'sRGB Rendering Intent':
break;
case 'Image Gamma':
break;
case 'ICC Profile Name':
break;
case 'Textual Data':
break;
case 'Last Modification Time':
break;
case 'Background Color':
break;
case 'Pixels Per Unit X':
break;
case 'Pixels Per Unit Y':
break;
case 'Unit Specifier':
break;
case 'Significant Bits':
break;
default:
break;
}
}
}

Expand Down Expand Up @@ -605,6 +692,9 @@ private static function createDirectoryWithName($directoryName)
case 'File':
$directory = new FileMetadataDirectory();
break;
case 'GIF Header':
$directory = new GifHeaderDirectory();
break;
case 'GPS':
$directory = new GpsDirectory();
break;
Expand Down
75 changes: 75 additions & 0 deletions src/main/php/Gomoob/MetadataExtractor/Metadata/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,81 @@ public function getDescription($tagType)

return $this->descriptor.getDescription($tagType);
}

/**
* Returns the specified tag's value as an int, if possible. Every attempt to represent the tag's value as an int
* is taken.
*
* Here is a list of the action taken depending upon the tag's original type:
* * int - Return unchanged.
* * Number - Return an int value (real numbers are truncated).
* * Rational - Truncate any fractional part and returns remaining int.
* * String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and
* OR).
* * Rational[] - Return int value of first item in array.
* * byte[] - Return int value of first item in array.
* * int[] - Return int value of first item in array.
*
* @throws MetadataException if no value exists for tagType or if it cannot be converted to an int.
*/
public function getInt($tagType)
{
$integer = $this->getInteger($tagType);

if ($integer !== null) {
return $integer;
}

$o = $this->getObject($tagType);

if ($o === null) {
throw new MetadataException(
"Tag '" . $this->getTagName($tagType) . "' has not been set -- check using containsTag() first"
);
}

throw new MetadataException(
"Tag '" . $tagType . "' cannot be converted to int. It is of type '" . $o->getClass() . "'."
);
}

/**
* Returns the specified tag's value as an Integer, if possible. Every attempt to represent the tag's value as an
* Integer is taken.
*
* Here is a list of the action taken depending upon the tag's original type:
* * int - Return unchanged
* * Number - Return an int value (real numbers are truncated)
* * Rational - Truncate any fractional part and returns remaining int
* * String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and OR)
* * Rational[] - Return int value of first item in array if length > 0
* * byte[] - Return int value of first item in array if length > 0
* * int[] - Return int value of first item in array if length > 0
*
* If the value is not found or cannot be converted to int, <code>null</code> is returned.
*/
public function getInteger($tagType)
{
// FIXME: This method has to be reviewed

$o = $this->getObject($tagType);

if ($o === null) {
return null;
}

if (is_int($o)) {
return $o;
} elseif (is_string($o)) {
return intval($o);
} elseif (is_array($o)) {
if (count($o) === 1) {
return intval($o[0]);
}
}

return null;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* gomoob/php-metadata-extractor
*
* @copyright Copyright (c) 2016, GOMOOB SARL (http://gomoob.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE.md file)
*/
namespace Gomoob\MetadataExtractor\Metadata\Gif;

use Gomoob\MetadataExtractor\Metadata\TagDescriptor;

/**
* @author Baptiste GAILLARD (baptiste.gaillard@gomoob.com)
*/
class GifHeaderDescriptor extends TagDescriptor
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* gomoob/php-metadata-extractor
*
* @copyright Copyright (c) 2016, GOMOOB SARL (http://gomoob.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE.md file)
*/
namespace Gomoob\MetadataExtractor\Metadata\Gif;

use Gomoob\MetadataExtractor\Metadata\Directory;

/**
* @author Baptiste GAILLARD (baptiste.gaillard@gomoob.com)
*/
class GifHeaderDirectory extends Directory
{
const TAG_GIF_FORMAT_VERSION = 1;
const TAG_IMAGE_WIDTH = 2;
const TAG_IMAGE_HEIGHT = 3;
const TAG_COLOR_TABLE_SIZE = 4;
const TAG_IS_COLOR_TABLE_SORTED = 5;
const TAG_BITS_PER_PIXEL = 6;
const TAG_HAS_GLOBAL_COLOR_TABLE = 7;
/**
* @deprecated use {@link #TAG_BACKGROUND_COLOR_INDEX} instead.
*/
const TAG_TRANSPARENT_COLOR_INDEX = 8;
const TAG_BACKGROUND_COLOR_INDEX = 8;
const TAG_PIXEL_ASPECT_RATIO = 9;

private static $tagNameMap = [
self::TAG_GIF_FORMAT_VERSION => "GIF Format Version",
self::TAG_IMAGE_HEIGHT => "Image Height",
self::TAG_IMAGE_WIDTH => "Image Width",
self::TAG_COLOR_TABLE_SIZE => "Color Table Size",
self::TAG_IS_COLOR_TABLE_SORTED => "Is Color Table Sorted",
self::TAG_BITS_PER_PIXEL => "Bits per Pixel",
self::TAG_HAS_GLOBAL_COLOR_TABLE => "Has Global Color Table",
self::TAG_BACKGROUND_COLOR_INDEX => "Background Color Index",
self::TAG_PIXEL_ASPECT_RATIO => "Pixel Aspect Ratio"
];

public function __construct()
{
$this->setDescriptor(new GifHeaderDescriptor($this));
}

/**
* {@inheritDoc}
*/
public function getName()
{
return 'GIF Header';
}

/**
* {@inheritDoc}
*/
protected function getTagNameMap()
{
return static::$tagNameMap;
}
}
Loading

0 comments on commit d651b25

Please sign in to comment.