Skip to content

Commit d651b25

Browse files
committed
Prepare first 2.9.1-alpha.1 version.
1 parent cb32625 commit d651b25

File tree

13 files changed

+477
-88
lines changed

13 files changed

+477
-88
lines changed

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module.exports = function(grunt) {
4747

4848
options: {
4949
bin : 'vendor/bin/phpunit',
50-
configuration : 'phpunit.xml.dist',
51-
group : 'ImageMetadataReader.Dotnet256x256AlphaPaletteTest'
50+
configuration : 'phpunit.xml.dist'//,
51+
//group : 'ImageMetadataReader.FujiFilmFinePixS1ProTest'
5252
}
5353

5454
}, /* PHPUnit Task */

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ Metadata metadata = ImageMetadataReader.readMetadata(imagePath);
2424

2525
## Installation
2626

27+
The easiest way to install the library is to use [composer](https://getcomposer.org/ "composer") and define the
28+
following dependency inside your `composer.json` file :
29+
30+
```json
31+
{
32+
"require": {
33+
"gomoob/php-metadata-extractor": "~2.9"
34+
}
35+
}
36+
```
37+
38+
Please also note that because the library is a wrapper around a Java library the `java` executable must be available
39+
in your `PATH` variable.
40+
41+
## Versioning
42+
43+
To easier version identification the version of `php-metadata-extractor` will always be aligned with the version
44+
of the Java `metadata-extractor`.
45+
46+
Stable versions of `php-metadata-extrator` will be equal to `X.Y.Z-N` where `N` represents a patch number
47+
associated to `php-metadata-extractor`.
48+
49+
Unstable or uncomplete versions of `php-metadata-extractor` will be equal to `X.Y.Z-alpha.N` or
50+
`X.Y.Z-beta.N`.
51+
2752
## About Gomoob
2853

2954
At [Gomoob](https://www.gomoob.com "Gomoob") we build high quality software with awesome Open Source frameworks

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name" : "gomoob/php-metadata-extractor",
33
"description" : "PHP wrapper to easily call the Java metadata-extrator library.",
4-
"version" : "1.0.0",
4+
"version" : "2.9.1-alpha.1",
55
"license" : "MIT",
66
"type" : "library",
77
"keywords" : [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gomoob-php-metadata-extractor",
3-
"version": "1.0.0",
3+
"version": "2.9.1-alpha.1",
44
"license": "MIT",
55
"repository" : {
66
"type" : "git",

src/main/php/Gomoob/MetadataExtractor/Imaging/ImageMetadataReader.php

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

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

1111
use Gomoob\BinaryDriver\MetadataExtractorDriver;
@@ -32,6 +32,7 @@
3232
use Gomoob\MetadataExtractor\Metadata\Exif\GpsDirectory;
3333
use Gomoob\MetadataExtractor\Lang\Rational;
3434
use Gomoob\MetadataExtractor\Metadata\Png\PngDirectory;
35+
use Gomoob\MetadataExtractor\Metadata\Gif\GifHeaderDirectory;
3536

3637
/**
3738
* Reads metadata from any supported file format.
@@ -60,26 +61,45 @@
6061
*/
6162
class ImageMetadataReader
6263
{
64+
/**
65+
* The last console output, this property is only defined for the PHP version of the library. The PHP version of
66+
* the library parses the console output of the Java `metadata-extractor` library, ths variable contains the last
67+
* console output.
68+
*
69+
* @var string
70+
*/
71+
private static $lastOutput;
72+
6373
/**
6474
* The {@link MetadataExtractorDriver} driver used to manage calls to the `metadata-extractor` library.
6575
*
6676
* @var \Gomoob\MetadataExtractor\Driver\MetadataExtractorDriver
6777
*/
6878
private $metadataExtractorDriver;
6979

80+
/**
81+
* Gets the last console output.
82+
*
83+
* @return string the last console output.
84+
*/
85+
public static function getLastOutput()
86+
{
87+
return static::$lastOutput;
88+
}
89+
7090
public static function readMetadata($file)
7191
{
7292
$metadata = new Metadata();
7393

7494
$metadataExtractorDriver = MetadataExtractorDriver::create();
75-
$output = $metadataExtractorDriver->command(
95+
static::$lastOutput = $metadataExtractorDriver->command(
7696
[
7797
$file
7898
]
7999
);
80100

81101
// Parse each line of the output
82-
foreach (explode(PHP_EOL, $output) as $line) {
102+
foreach (explode(PHP_EOL, static::$lastOutput) as $line) {
83103
$trimedLine = trim($line);
84104

85105
// We ignore empty lines, metadata-extractor outputs empty line to have a human readable console output but
@@ -438,6 +458,30 @@ private static function addTagToDirectory(Directory $directory, $tagLine)
438458
default:
439459
// TODO: Error
440460
}
461+
} elseif ($directory instanceof GifHeaderDirectory) {
462+
switch ($nameAndDescription[0]) {
463+
case 'GIF Format Version':
464+
break;
465+
case 'Image Height':
466+
$directory->setInt(GifHeaderDirectory::TAG_IMAGE_HEIGHT, intval($nameAndDescription[1]));
467+
break;
468+
case 'Image Width':
469+
$directory->setInt(GifHeaderDirectory::TAG_IMAGE_WIDTH, intval($nameAndDescription[1]));
470+
break;
471+
case 'Color Table Size':
472+
break;
473+
case 'Is Color Table Sorted':
474+
break;
475+
case 'Bits per Pixel':
476+
break;
477+
case 'Has Global Color Table':
478+
break;
479+
case 'Background Color Index':
480+
break;
481+
case 'Pixel Aspect Ratio':
482+
break;
483+
default:
484+
}
441485
} elseif ($directory instanceof JfifDirectory) {
442486
switch ($nameAndDescription[0]) {
443487
case 'Version':
@@ -533,9 +577,52 @@ private static function addTagToDirectory(Directory $directory, $tagLine)
533577
// TODO: Exception
534578
}
535579
} elseif ($directory instanceof PngDirectory) {
536-
// var_dump($tagLine);
537-
// var_dump($nameAndDescription[0]);
538-
// var_dump($nameAndDescription[1]);
580+
// var_dump($tagLine);
581+
// var_dump($nameAndDescription);
582+
switch ($nameAndDescription[0]) {
583+
case 'Image Height':
584+
$directory->setInt(PngDirectory::TAG_IMAGE_HEIGHT, intval($nameAndDescription[1]));
585+
break;
586+
case 'Image Width':
587+
$directory->setInt(PngDirectory::TAG_IMAGE_WIDTH, intval($nameAndDescription[1]));
588+
break;
589+
case 'Bits Per Sample':
590+
break;
591+
case 'Color Type':
592+
break;
593+
case 'Compression Type':
594+
break;
595+
case 'Filter Method':
596+
break;
597+
case 'Interlace Method':
598+
break;
599+
case 'Palette Size':
600+
break;
601+
case 'Palette Has Transparency':
602+
break;
603+
case 'sRGB Rendering Intent':
604+
break;
605+
case 'Image Gamma':
606+
break;
607+
case 'ICC Profile Name':
608+
break;
609+
case 'Textual Data':
610+
break;
611+
case 'Last Modification Time':
612+
break;
613+
case 'Background Color':
614+
break;
615+
case 'Pixels Per Unit X':
616+
break;
617+
case 'Pixels Per Unit Y':
618+
break;
619+
case 'Unit Specifier':
620+
break;
621+
case 'Significant Bits':
622+
break;
623+
default:
624+
break;
625+
}
539626
}
540627
}
541628

@@ -605,6 +692,9 @@ private static function createDirectoryWithName($directoryName)
605692
case 'File':
606693
$directory = new FileMetadataDirectory();
607694
break;
695+
case 'GIF Header':
696+
$directory = new GifHeaderDirectory();
697+
break;
608698
case 'GPS':
609699
$directory = new GpsDirectory();
610700
break;

src/main/php/Gomoob/MetadataExtractor/Metadata/Directory.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,81 @@ public function getDescription($tagType)
6262

6363
return $this->descriptor.getDescription($tagType);
6464
}
65+
66+
/**
67+
* Returns the specified tag's value as an int, if possible. Every attempt to represent the tag's value as an int
68+
* is taken.
69+
*
70+
* Here is a list of the action taken depending upon the tag's original type:
71+
* * int - Return unchanged.
72+
* * Number - Return an int value (real numbers are truncated).
73+
* * Rational - Truncate any fractional part and returns remaining int.
74+
* * String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and
75+
* OR).
76+
* * Rational[] - Return int value of first item in array.
77+
* * byte[] - Return int value of first item in array.
78+
* * int[] - Return int value of first item in array.
79+
*
80+
* @throws MetadataException if no value exists for tagType or if it cannot be converted to an int.
81+
*/
82+
public function getInt($tagType)
83+
{
84+
$integer = $this->getInteger($tagType);
85+
86+
if ($integer !== null) {
87+
return $integer;
88+
}
89+
90+
$o = $this->getObject($tagType);
91+
92+
if ($o === null) {
93+
throw new MetadataException(
94+
"Tag '" . $this->getTagName($tagType) . "' has not been set -- check using containsTag() first"
95+
);
96+
}
97+
98+
throw new MetadataException(
99+
"Tag '" . $tagType . "' cannot be converted to int. It is of type '" . $o->getClass() . "'."
100+
);
101+
}
102+
103+
/**
104+
* Returns the specified tag's value as an Integer, if possible. Every attempt to represent the tag's value as an
105+
* Integer is taken.
106+
*
107+
* Here is a list of the action taken depending upon the tag's original type:
108+
* * int - Return unchanged
109+
* * Number - Return an int value (real numbers are truncated)
110+
* * Rational - Truncate any fractional part and returns remaining int
111+
* * String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and OR)
112+
* * Rational[] - Return int value of first item in array if length > 0
113+
* * byte[] - Return int value of first item in array if length > 0
114+
* * int[] - Return int value of first item in array if length > 0
115+
*
116+
* If the value is not found or cannot be converted to int, <code>null</code> is returned.
117+
*/
118+
public function getInteger($tagType)
119+
{
120+
// FIXME: This method has to be reviewed
121+
122+
$o = $this->getObject($tagType);
123+
124+
if ($o === null) {
125+
return null;
126+
}
127+
128+
if (is_int($o)) {
129+
return $o;
130+
} elseif (is_string($o)) {
131+
return intval($o);
132+
} elseif (is_array($o)) {
133+
if (count($o) === 1) {
134+
return intval($o[0]);
135+
}
136+
}
137+
138+
return null;
139+
}
65140

66141
/**
67142
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* gomoob/php-metadata-extractor
5+
*
6+
* @copyright Copyright (c) 2016, GOMOOB SARL (http://gomoob.com)
7+
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE.md file)
8+
*/
9+
namespace Gomoob\MetadataExtractor\Metadata\Gif;
10+
11+
use Gomoob\MetadataExtractor\Metadata\TagDescriptor;
12+
13+
/**
14+
* @author Baptiste GAILLARD ([email protected])
15+
*/
16+
class GifHeaderDescriptor extends TagDescriptor
17+
{
18+
19+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/**
4+
* gomoob/php-metadata-extractor
5+
*
6+
* @copyright Copyright (c) 2016, GOMOOB SARL (http://gomoob.com)
7+
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE.md file)
8+
*/
9+
namespace Gomoob\MetadataExtractor\Metadata\Gif;
10+
11+
use Gomoob\MetadataExtractor\Metadata\Directory;
12+
13+
/**
14+
* @author Baptiste GAILLARD ([email protected])
15+
*/
16+
class GifHeaderDirectory extends Directory
17+
{
18+
const TAG_GIF_FORMAT_VERSION = 1;
19+
const TAG_IMAGE_WIDTH = 2;
20+
const TAG_IMAGE_HEIGHT = 3;
21+
const TAG_COLOR_TABLE_SIZE = 4;
22+
const TAG_IS_COLOR_TABLE_SORTED = 5;
23+
const TAG_BITS_PER_PIXEL = 6;
24+
const TAG_HAS_GLOBAL_COLOR_TABLE = 7;
25+
/**
26+
* @deprecated use {@link #TAG_BACKGROUND_COLOR_INDEX} instead.
27+
*/
28+
const TAG_TRANSPARENT_COLOR_INDEX = 8;
29+
const TAG_BACKGROUND_COLOR_INDEX = 8;
30+
const TAG_PIXEL_ASPECT_RATIO = 9;
31+
32+
private static $tagNameMap = [
33+
self::TAG_GIF_FORMAT_VERSION => "GIF Format Version",
34+
self::TAG_IMAGE_HEIGHT => "Image Height",
35+
self::TAG_IMAGE_WIDTH => "Image Width",
36+
self::TAG_COLOR_TABLE_SIZE => "Color Table Size",
37+
self::TAG_IS_COLOR_TABLE_SORTED => "Is Color Table Sorted",
38+
self::TAG_BITS_PER_PIXEL => "Bits per Pixel",
39+
self::TAG_HAS_GLOBAL_COLOR_TABLE => "Has Global Color Table",
40+
self::TAG_BACKGROUND_COLOR_INDEX => "Background Color Index",
41+
self::TAG_PIXEL_ASPECT_RATIO => "Pixel Aspect Ratio"
42+
];
43+
44+
public function __construct()
45+
{
46+
$this->setDescriptor(new GifHeaderDescriptor($this));
47+
}
48+
49+
/**
50+
* {@inheritDoc}
51+
*/
52+
public function getName()
53+
{
54+
return 'GIF Header';
55+
}
56+
57+
/**
58+
* {@inheritDoc}
59+
*/
60+
protected function getTagNameMap()
61+
{
62+
return static::$tagNameMap;
63+
}
64+
}

0 commit comments

Comments
 (0)