Skip to content

Commit

Permalink
Fix 1548 (#55)
Browse files Browse the repository at this point in the history
* New MapperAbstract class with a recursive trim
* Support IPTC:CopyrightNotice
* Support more EXIF tags
* Support EXIF ImageDescription
* Add more test images
* Fix the GPS rounding code
* fix Copyrights

Co-authored-by: ildyria <[email protected]>
  • Loading branch information
kamil4 and ildyria authored Oct 28, 2022
1 parent ada5def commit c0d1ce4
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 189 deletions.
27 changes: 0 additions & 27 deletions CHANGELOG.rst

This file was deleted.

3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (C) 2013 Tom Van Herreweghe, http://theanalogguy.be
Copyright (C) 2013-2019 Tom Van Herreweghe, http://theanalogguy.be
Copyright (C) 2020 LycheeOrg, https://lycheeorg.github.io

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
9 changes: 0 additions & 9 deletions lib/PHPExif/Adapter/AdapterAbstract.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* PHP Exif Reader Adapter Abstract: Common functionality for adapters
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Reader
*/

namespace PHPExif\Adapter;

Expand Down
7 changes: 0 additions & 7 deletions lib/PHPExif/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php
/**
* PHP Exif Reader Adapter Interface: Defines the interface for reader adapters
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Reader
* @codeCoverageIgnore
*/

Expand Down
9 changes: 0 additions & 9 deletions lib/PHPExif/Adapter/Exiftool.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* PHP Exif Exiftool Reader Adapter
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Reader
*/

namespace PHPExif\Adapter;

Expand Down
11 changes: 2 additions & 9 deletions lib/PHPExif/Adapter/ImageMagick.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* PHP Exif Imagick Reader Adapter
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Reader
*/

namespace PHPExif\Adapter;

Expand Down Expand Up @@ -83,6 +74,8 @@ public function getExifFromFile(string $file) : Exif
}

$data = array_merge($data_exif, $data_iptc, $additional_data);
// Force UTF8 encoding
$data = $this->convertToUTF8($data);

// map the data:
$mapper = $this->getMapper();
Expand Down
12 changes: 1 addition & 11 deletions lib/PHPExif/Adapter/Native.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?php
/**
* PHP Exif Native Reader Adapter
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Reader
*/

namespace PHPExif\Adapter;

use PHPExif\Exif;
use Safe\Exceptions\ImageException;
use Throwable;

use function Safe\mime_content_type;
use function Safe\filesize;
Expand Down Expand Up @@ -229,7 +219,7 @@ public function getExifFromFile(string $file) : Exif
// Fail silently
}
}

// Force UTF8 encoding
$data = $this->convertToUTF8($data);

Expand Down
7 changes: 0 additions & 7 deletions lib/PHPExif/Adapter/NoAdapterException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php
/**
* PHP Exif Reader Adapter Interface: Defines the interface for reader adapters
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Reader
* @codeCoverageIgnore
*/

Expand Down
10 changes: 0 additions & 10 deletions lib/PHPExif/Exif.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* PHP Exif Reader: Reads EXIF metadata from a file, without having to install additional PHP modules
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2013 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Exif
*/

namespace PHPExif;

Expand All @@ -20,7 +11,6 @@
*
* @category PHPExif
* @package Exif
* @
*/
class Exif
{
Expand Down
7 changes: 0 additions & 7 deletions lib/PHPExif/Hydrator/HydratorInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php
/**
* PHP Exif Hydrator Interface: Defines the interface for a hydrator
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2015 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Hydrator
* @codeCoverageIgnore
*/

Expand Down
10 changes: 0 additions & 10 deletions lib/PHPExif/Hydrator/Mutator.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
<?php
/**
* PHP Exif Mutator Hydrator: Hydrate an object
* by manipulating the object with its mutator methods
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2015 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Hydrator
*/

namespace PHPExif\Hydrator;

Expand Down
11 changes: 7 additions & 4 deletions lib/PHPExif/Mapper/Exiftool.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
* @category PHPExif
* @package Mapper
*/
class Exiftool implements MapperInterface
class Exiftool extends MapperAbstract
{
public const APERTURE = 'Composite:Aperture';
public const APPROXIMATEFOCUSDISTANCE = 'XMP-aux:ApproximateFocusDistance';
public const ARTIST = 'IFD0:Artist';
public const CAPTIONABSTRACT = 'IPTC:Caption-Abstract';
public const COLORSPACE = 'ExifIFD:ColorSpace';
public const COPYRIGHT = 'IFD0:Copyright';
public const COPYRIGHT_IPTC = 'IPTC:CopyrightNotice';
public const DATETIMEORIGINAL = 'ExifIFD:DateTimeOriginal';
public const CREDIT = 'IPTC:Credit';
public const EXPOSURETIME = 'ExifIFD:ExposureTime';
Expand Down Expand Up @@ -109,6 +110,7 @@ class Exiftool implements MapperInterface
self::MODEL => Exif::CAMERA,
self::COLORSPACE => Exif::COLORSPACE,
self::COPYRIGHT => Exif::COPYRIGHT,
self::COPYRIGHT_IPTC => Exif::COPYRIGHT,
self::DATETIMEORIGINAL => Exif::CREATION_DATE,
self::CREDIT => Exif::CREDIT,
self::EXPOSURETIME => Exif::EXPOSURE,
Expand Down Expand Up @@ -209,6 +211,7 @@ public function mapRawData(array $data): array
}

$key = $this->map[$field];
$value = $this->trim($value);

// manipulate the value if necessary
switch ($field) {
Expand Down Expand Up @@ -388,13 +391,13 @@ public function mapRawData(array $data): array
/**
* Extract GPS coordinates from formatted string
*
* @param string $coordinates
* @param mixed $coordinates
* @return float|false
*/
protected function extractGPSCoordinates(string $coordinates): float|false
protected function extractGPSCoordinates(mixed $coordinates): float|false
{
if (is_numeric($coordinates) === true || $this->numeric === true) {
return ((float) $coordinates);
return round(floatval($coordinates), self::ROUNDING_PRECISION);
} else {
if (preg_match('!^([0-9.]+) deg ([0-9.]+)\' ([0-9.]+)"!', $coordinates, $matches) === 0) {
return false;
Expand Down
14 changes: 3 additions & 11 deletions lib/PHPExif/Mapper/FFprobe.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* PHP Exif Native Mapper
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2015 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Mapper
*/

namespace PHPExif\Mapper;

Expand All @@ -24,7 +15,7 @@
* @category PHPExif
* @package Mapper
*/
class FFprobe implements MapperInterface
class FFprobe extends MapperAbstract
{
const HEIGHT = 'height';
const WIDTH = 'width';
Expand Down Expand Up @@ -114,6 +105,7 @@ public function mapRawData(array $data) : array
}

$key = $this->map[$field];
$value = $this->trim($value);

// manipulate the value if necessary
switch ($field) {
Expand Down Expand Up @@ -286,7 +278,7 @@ public function convertDMStoDecimal(
if ($sign === '-') {
$decimal = -1.0 * $decimal;
}
return $decimal;
return round($decimal, self::ROUNDING_PRECISION);
}

/**
Expand Down
22 changes: 9 additions & 13 deletions lib/PHPExif/Mapper/ImageMagick.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* PHP Imagick Exiftool Mapper
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2015 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Mapper
*/

namespace PHPExif\Mapper;

Expand All @@ -26,13 +17,15 @@
* @category PHPExif
* @package Mapper
*/
class ImageMagick implements MapperInterface
class ImageMagick extends MapperAbstract
{
const APERTURE = 'exif:FNumber';
const ARTIST = 'exif:Artist';
const COLORSPACE = 'exif:ColorSpace';
const COPYRIGHT = 'exif:Copyright';
const CREATION_DATE = 'date:create';
const DATETIMEORIGINAL = 'exif:DateTimeOriginal';
const DESCRIPTION = 'exif:ImageDescription ';
const DESCRIPTION = 'exif:ImageDescription';
const EXPOSURETIME = 'exif:ExposureTime';
const FILESIZE = 'filesize';
const FILENAME = 'filename';
Expand All @@ -58,7 +51,7 @@ class ImageMagick implements MapperInterface
const YRESOLUTION = 'exif:YResolution';
const TITLE = 'iptc:title';
const KEYWORDS = 'iptc:keywords';
const COPYRIGHT = 'iptc:copyright';
const COPYRIGHT_IPTC = 'iptc:copyright';
const CAPTION = 'iptc:caption';
const HEADLINE = 'iptc:headline';
const CREDIT = 'iptc:credit';
Expand All @@ -78,7 +71,9 @@ class ImageMagick implements MapperInterface
*/
protected array $map = array(
self::APERTURE => Exif::APERTURE,
self::ARTIST => Exif::AUTHOR,
self::COLORSPACE => Exif::COLORSPACE,
self::COPYRIGHT => Exif::COPYRIGHT,
self::CREATION_DATE => Exif::CREATION_DATE,
self::DATETIMEORIGINAL => Exif::CREATION_DATE,
self::DESCRIPTION => Exif::DESCRIPTION,
Expand Down Expand Up @@ -107,7 +102,7 @@ class ImageMagick implements MapperInterface
self::YRESOLUTION => Exif::VERTICAL_RESOLUTION,
self::TITLE => Exif::TITLE,
self::KEYWORDS => Exif::KEYWORDS,
self::COPYRIGHT => Exif::COPYRIGHT,
self::COPYRIGHT_IPTC => Exif::COPYRIGHT,
self::CAPTION => Exif::CAPTION,
self::HEADLINE => Exif::HEADLINE,
self::CREDIT => Exif::CREDIT,
Expand Down Expand Up @@ -139,6 +134,7 @@ public function mapRawData(array $data) : array
}

$key = $this->map[$field];
$value = $this->trim($value);

// manipulate the value if necessary
switch ($field) {
Expand Down
33 changes: 33 additions & 0 deletions lib/PHPExif/Mapper/MapperAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace PHPExif\Mapper;

/**
* PHP Exif Mapper Abstract
*
* Implements common functionality for data mappers
*
* @category PHPExif
* @package Mapper
*/
abstract class MapperAbstract implements MapperInterface
{
/**
* Trim whitespaces recursively
*
* @param mixed $data
* @return mixed
*/
public function trim(mixed $data) : mixed
{
if (is_array($data)) {
/** @var mixed $v */
foreach ($data as $k => $v) {
$data[$k] = $this->trim($v);
}
} elseif (is_string($data)) {
$data = trim($data);
}
return $data;
}
}
7 changes: 0 additions & 7 deletions lib/PHPExif/Mapper/MapperInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php
/**
* PHP Exif Mapper Interface: Defines the interface for data mappers
*
* @link http://github.com/miljar/PHPExif for the canonical source repository
* @copyright Copyright (c) 2015 Tom Van Herreweghe <[email protected]>
* @license http://github.com/miljar/PHPExif/blob/master/LICENSE MIT License
* @category PHPExif
* @package Mapper
* @codeCoverageIgnore
*/

Expand Down
Loading

0 comments on commit c0d1ce4

Please sign in to comment.