-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4ed6498
Showing
8 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.bat] | ||
end_of_line = crlf | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.twig] | ||
insert_final_newline = false | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Define the line ending behavior of the different file extensions | ||
# Set default behavior, in case users don't have core.autocrlf set. | ||
* text=auto | ||
* text eol=lf | ||
|
||
# Explicitly declare text files we want to always be normalized and converted | ||
# to native line endings on checkout. | ||
*.php text | ||
*.default text | ||
*.ctp text | ||
*.sql text | ||
*.md text | ||
*.po text | ||
*.js text | ||
*.css text | ||
*.ini text | ||
*.properties text | ||
*.txt text | ||
*.xml text | ||
*.svg text | ||
*.yml text | ||
.htaccess text | ||
|
||
# Declare files that will always have CRLF line endings on checkout. | ||
*.bat eol=crlf | ||
|
||
# Declare files that will always have LF line endings on checkout. | ||
*.pem eol=lf | ||
|
||
# Denote all files that are truly binary and should not be modified. | ||
*.dbf binary | ||
*.prj binary | ||
*.shp binary | ||
*.shx binary | ||
*.sld binary | ||
*.png binary | ||
*.jpg binary | ||
*.gif binary | ||
*.ico binary | ||
*.mo binary | ||
*.pdf binary | ||
*.phar binary | ||
*.woff binary | ||
*.woff2 binary | ||
*.ttf binary | ||
*.otf binary | ||
*.eot binary | ||
*.gz binary | ||
*.bz2 binary | ||
*.7z binary | ||
*.zip binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# CakePHP specific files # | ||
########################## | ||
/config/app.php | ||
/config/.env | ||
/logs/* | ||
/tmp/* | ||
/vendor/* | ||
/webroot/files/* | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
Icon? | ||
ehthumbs.db | ||
Thumbs.db | ||
*.zip | ||
|
||
# Tool specific files # | ||
####################### | ||
/.vscode | ||
/composer.lock | ||
/.phpdoc | ||
# vim | ||
*~ | ||
*.swp | ||
*.swo | ||
# sublime text & textmate | ||
*.sublime-* | ||
*.stTheme.cache | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
# Eclipse | ||
.settings/* | ||
# JetBrains, aka PHPStorm, IntelliJ IDEA | ||
.idea/* | ||
# NetBeans | ||
nbproject/* | ||
# Visual Studio Code | ||
.vscode | ||
# Sass preprocessor | ||
.sass-cache/ | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Fawno | ||
|
||
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 the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[![GitHub license](https://img.shields.io/github/license/fawno/SimpleIPTC)](https://github.com/fawno/SimpleIPTC/blob/master/LICENSE) | ||
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/fawno/SimpleIPTC)](https://github.com/fawno/SimpleIPTC/tags) | ||
[![GitHub release](https://img.shields.io/github/release/fawno/SimpleIPTC)](https://github.com/fawno/SimpleIPTC/releases) | ||
[![Packagist](https://img.shields.io/packagist/v/fawno/simpleiptc)](https://packagist.org/packages/fawno/simpleiptc) | ||
[![Packagist Downloads](https://img.shields.io/packagist/dt/fawno/simpleiptc)](https://packagist.org/packages/fawno/simpleiptc/stats) | ||
[![GitHub issues](https://img.shields.io/github/issues/fawno/SimpleIPTC)](https://github.com/fawno/SimpleIPTC/issues) | ||
[![GitHub forks](https://img.shields.io/github/forks/fawno/SimpleIPTC)](https://github.com/fawno/SimpleIPTC/network) | ||
[![GitHub stars](https://img.shields.io/github/stars/fawno/SimpleIPTC)](https://github.com/fawno/SimpleIPTC/stargazers) | ||
|
||
# SimpleSVG | ||
|
||
Simple PHP class for IPTC documents | ||
|
||
## Instalation | ||
|
||
```sh | ||
php composer.phar require "fawno/simpleiptc" | ||
``` | ||
|
||
```php | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
use SimpleIPTC\SimpleIPTC; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "fawno/simpleiptc", | ||
"description": "Simple PHP class for IPTC documents", | ||
"type": "library", | ||
"keywords": ["iptc"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Fernando Herrero", | ||
"homepage": "https://lab.fawno.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SimpleIPTC\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* SimpleIPTC: IPTC convenience class (https://github.com/fawno/SimpleIPTC) | ||
* Copyright (c) Fernando Herrero (https://github.com/alpha) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Fernando Herrero (https://github.com/alpha) | ||
* @link https://github.com/fawno/SimpleIPTC SimpleIPTC | ||
* @since 0.0.1 | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace SimpleIPTC; | ||
|
||
/** @package SimpleIPTC */ | ||
class SimpleIPTC { | ||
const IPTC_TAGS = [ | ||
'1#000' => [ | ||
'name' => 'EnvelopeRecordVersion', | ||
'format' => 'n', // int16u big endian | ||
], | ||
'1#020' => [ | ||
'name' => 'FileFormat', | ||
'format' => 'n', // int16u big endian | ||
], | ||
'1#022' => [ | ||
'name' => 'FileVersion', | ||
'format' => 'n', // int16u big endian | ||
], | ||
'2#000' => [ | ||
'name' => 'ApplicationRecordVersion', | ||
'format' => 'n', // int16u big endian | ||
], | ||
'2#055' => [ | ||
'name' => 'DateCreated', | ||
'format' => 'a*', | ||
], | ||
'2#243' => [ | ||
'name' => 'CustomData', | ||
'format' => 'a*', | ||
], | ||
]; | ||
|
||
/** | ||
* @param string $bin | ||
* @return array | ||
*/ | ||
public static function bin2iptc (string $bin) : array { | ||
$iptc = []; | ||
|
||
$fp = fopen('php://memory','rb+'); | ||
fwrite ($fp, $bin); | ||
rewind($fp); | ||
|
||
while ("\x1C" == fread($fp, 1)) { | ||
$parts = unpack('Crecord/Cid/nlength', fread($fp, 4)); | ||
|
||
$tag = sprintf('%u#%03u', $parts['record'], $parts['id']); | ||
$format = self::IPTC_TAGS[$tag]['format'] ?? 'a*'; | ||
|
||
if ($parts['length'] == 0x8004) { | ||
$parts = unpack('Nlength', fread($fp, 4)); | ||
} | ||
|
||
$iptc[] = [ | ||
'tag' => $tag, | ||
'name' => self::IPTC_TAGS[$tag]['name'] ?? null, | ||
'value' => current(unpack($format, fread($fp, $parts['length']))), | ||
]; | ||
} | ||
|
||
fclose($fp); | ||
|
||
return $iptc; | ||
} | ||
|
||
/** | ||
* @param array $iptc | ||
* @return string | ||
*/ | ||
public static function iptc2bin (array $iptc) : string { | ||
$data = ''; | ||
|
||
foreach ($iptc as $record) { | ||
if (!empty($record['value'])) { | ||
$tag = $record['tag'] ?? null; | ||
$format = self::IPTC_TAGS[$tag]['format'] ?? 'a*'; | ||
$value = pack($format, $record['value']); | ||
$length = strlen($value); | ||
|
||
$data .= pack('C*', 0x1C, ...explode('#', $tag)); | ||
$data .= ($length < 0x8000) ? pack('n', $length) : pack('nN', 0x8004, $length); | ||
$data .= $value; | ||
} else { | ||
print_r($record); | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* SimpleIPTC: IPTC convenience class (https://github.com/fawno/SimpleIPTC) | ||
* Copyright (c) Fernando Herrero (https://github.com/alpha) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Fernando Herrero (https://github.com/alpha) | ||
* @link https://github.com/fawno/SimpleIPTC SimpleIPTC | ||
* @since 0.0.1 | ||
* @license https://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace SimpleIPTC; | ||
|
||
use \Throwable; | ||
use \Exception; | ||
|
||
/** | ||
* Provides custom exception class. | ||
* | ||
* @package SimpleIPTC | ||
* @used-by Fawno\PhpSerial\Serial | ||
* @used-by Fawno\PhpSerial\SerialDio | ||
* @used-by Fawno\PhpSerial\SerialFile | ||
* @used-by Fawno\PhpSerial\SerialFileDawing | ||
* @used-by Fawno\PhpSerial\SerialFileLinux | ||
* @used-by Fawno\PhpSerial\SerialFileWindows | ||
*/ | ||
class SimpleIPTCException extends Exception { | ||
public const ERROR_INDETERMINATE = 0; | ||
|
||
protected int $severity; | ||
|
||
/** | ||
* Construct the exception. Note: The message is NOT binary safe. | ||
* | ||
* @param string $message | ||
* [optional] The Exception message to throw. | ||
* | ||
* @param int $code | ||
* [optional] The Exception code. | ||
* | ||
* @param int $severity | ||
* [optional] The Exception severity. | ||
* Note: | ||
* While the severity can be any int value, it is intended that the error constants be used. | ||
* | ||
* @param string|null $filename | ||
* [optional] The filename where the exception is thrown. | ||
* | ||
* @param int|null $line | ||
* [optional] The line number where the exception is thrown. | ||
* | ||
* @param Throwable|null $previous | ||
* [optional] The previous throwable used for the exception chaining. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct (string $message = '', int $code = self::ERROR_INDETERMINATE, int $severity = E_ERROR, string $filename = null, int $line = null , Throwable $previous = null) { | ||
$this->severity = $severity; | ||
|
||
if (!is_null($filename)) { | ||
$this->filename = $filename; | ||
} | ||
|
||
if (!is_null($line)) { | ||
$this->line = $line; | ||
} | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
/** | ||
* Gets the exception severity | ||
* | ||
* @return int | ||
* Returns the severity of the exception. | ||
*/ | ||
public function getSeverity () : int { | ||
return $this->severity; | ||
} | ||
} |