Skip to content

Commit

Permalink
Merge pull request #12 from JellyBellyDev/enhancement/php74
Browse files Browse the repository at this point in the history
feat(engine): refactoring library to minor php version 7.4
  • Loading branch information
JellyBellyDev authored Oct 11, 2020
2 parents 8b2ed3a + 095e9f8 commit 7c25b6a
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 139 deletions.
34 changes: 0 additions & 34 deletions .docker/php71/Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions .docker/php74/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM php:7.4-cli

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends --allow-unauthenticated --no-upgrade \
git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

RUN install-php-extensions gd exif xdebug

COPY --from=composer /usr/bin/composer /usr/bin/composer
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ language: php
sudo: false

php:
- 7.1
- 7.2
- 7.3
- 7.4

cache:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v3.0.0
⚠ BREAKING CHANGES
- Refactoring library to minor php version `7.4`

## v2.0.0
⚠ BREAKING CHANGES
- Refactoring library to minor php version `7.1`
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Andrea Giannantonio
Copyright (c) 2014-2020 Andrea Giannantonio

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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ PHP library to fix image orientation by exif data with thanks to method [exif_re

## Image Example

| Input | Output |
|--- |--- |
| ![after](images/input_landscape_3.jpg) | ![output](images/output_landscape_3.jpg) |
![after](images/after_and_before.png)


## How to install
Expand Down Expand Up @@ -46,20 +44,20 @@ Dependencies are managed through composer:

```
$ docker-compose up --build -d
$ docker-compose run php71 composer install
$ docker-compose run php74 composer install
```


### Run phpunit:

```
$ docker-compose run php71 composer test
$ docker-compose run php74 composer test
```


### Run php-cs-fixer
``` bash
docker-compose run php71 composer cs-fixer
docker-compose run php74 composer cs-fixer
```


Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
}
},
"require": {
"php": "^7.1",
"php": "^7.4",
"ext-gd": "*",
"ext-exif": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^9.4",
"friendsofphp/php-cs-fixer": "^2.16"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '3.1'
services:

php71:
build: .docker/php71
php74:
build: .docker/php74
working_dir: /application
volumes:
- .:/application:cached
Binary file added images/after_and_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/input_landscape_3.jpg
Binary file not shown.
Binary file removed images/output_landscape_3.jpg
Binary file not shown.
37 changes: 17 additions & 20 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@

namespace ImageOrientationFix;

use Exception;
use RuntimeException;

/**
* Class Image
* @package ImageOrientationFix
*/
class Image
{
/** @var string */
private $filePathInput = null;
private $mimeType = null;
private $exifData = null;
private $orientation = null;
private $extension = null;
private static $mimeTypesValid = [
private ?string $filePathInput = null;
private ?string $mimeType = null;
private $exifData = null;
private ?int $orientation = null;
private ?string $extension = null;
private static array $mimeTypesValid = [
'jpe' => 'image/jpe',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpg',
Expand All @@ -41,12 +40,12 @@ public function __construct($filePathInput)

/**
* @param $filePathInput
* @throws Exception
* @throws RuntimeException
*/
private function setFilePathInput($filePathInput): void
{
if (!file_exists($filePathInput)) {
throw new Exception('FilePathInput not exists');
throw new RuntimeException('FilePathInput not exists');
}
$this->filePathInput = $filePathInput;
}
Expand All @@ -65,8 +64,8 @@ public function getFilePathInput(): string
private function setMimeType(): void
{
$mimeType = MimeType::get($this->getFilePathInput());
if (empty($mimeType) || !in_array($mimeType, self::$mimeTypesValid)) {
throw new Exception("$mimeType: mimeType not valid");
if (empty($mimeType) || !in_array($mimeType, self::$mimeTypesValid, true)) {
throw new RuntimeException("$mimeType: mimeType not valid");
}
$this->mimeType = $mimeType;
}
Expand Down Expand Up @@ -104,17 +103,15 @@ public function getExifData()
private function setOrientation(): void
{
$exifData = $this->getExifData();
if ($exifData && is_array($exifData) && array_key_exists('Orientation', $exifData)) {
if (1 <= $exifData['Orientation'] && $exifData['Orientation'] <= 8) {
$this->orientation = ($exifData && isset($exifData['Orientation'])) ? $exifData['Orientation'] : false;
}
if ($exifData && is_array($exifData) && array_key_exists('Orientation', $exifData) && 1 <= $exifData['Orientation'] && $exifData['Orientation'] <= 8) {
$this->orientation = $exifData['Orientation'];
}
}

/**
* @return int
* @return int|null
*/
public function getOrientation(): int
public function getOrientation(): ?int
{
return $this->orientation;
}
Expand All @@ -131,9 +128,9 @@ private function setExtension(): void
}

/**
* @return string
* @return string|null
*/
public function getExtension(): string
public function getExtension(): ?string
{
return $this->extension;
}
Expand Down
Loading

0 comments on commit 7c25b6a

Please sign in to comment.