Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM php:latest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move to a docker directory for consistency, see the other libraries.

Also update docker-compose.yml

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
zlib1g-dev \
unzip \
git \
zip \
libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd pdo pdo_mysql \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . .

RUN composer install

CMD ["vendor/bin/phpunit"]

21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "timeoutdigital/image-transform",
"type": "library",
"version": "master",
"version": "1.0.0",
"description": "Image Transform",
"keywords": ["image"],
"homepage": "http://timeout.com",
Expand All @@ -13,15 +13,20 @@
"email": "contact@timeout.com"
}
],

"require": {
"php": ">=5.3.2"
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^10"
},

"autoload": {
"psr-0": {
"ImageTransform": "src/"
"psr-4": {
"ImageTransform\\": "src/"
}
},
"config": {
"platform": {
"php": "8.2.0"
}
}
}
}

7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
php:
build: .
volumes:
- .:/app
working_dir: /app
command: sh -c "composer install && vendor/bin/phpunit"
38 changes: 8 additions & 30 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="true"
bootstrap="src/autoload.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
strict="true">

<phpunit
bootstrap="src/autoload.php"
colors="true"
stopOnFailure="false"
cacheResultFile=".phpunit.cache"
executionOrder="depends,defects"
>
<testsuites>
<testsuite name="ImageTransform Test Suite">
<directory>./tests/ImageTransform</directory>
<directory suffix="Test.php">./tests/ImageTransform</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/ImageTransform</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="build/coverage" title="ImageTransform"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
60 changes: 30 additions & 30 deletions src/ImageTransform/FileAccessAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@
*/
interface FileAccessAdapter
{
/**
* Create an image resource
*
* @param integer $width Width of the image to be created
* @param integer $height Height of the image to be created
*/
public function create($width, $height);
/**
* Create an image resource
*
* @param integer $width Width of the image to be created
* @param integer $height Height of the image to be created
*/
public function create($width, $height);

/**
* Open a resource for an Image
*
* @param string $filepath Location of the file to open
*/
public function open($filepath);
/**
* Open a resource for an Image
*
* @param string $filepath Location of the file to open
*/
public function open($filepath);

/**
* Flush an Image resource to stdout
*
* @param string $mimeType Mime type of the target file
*/
public function flush($mimeType = false);
/**
* Flush an Image resource to stdout
*
* @param string $mimeType Mime type of the target file
*/
public function flush($mimeType = false);

/**
* Save an Image resource under its current location
*/
public function save();
/**
* Save an Image resource under its current location
*/
public function save();

/**
* Save an Image resource under a given filepath
*
* @param string $filepath Locastion where to save the resource
* @param string $mimeType Mime type of the target file
*/
public function saveAs($filepath, $mimeType = false);
/**
* Save an Image resource under a given filepath
*
* @param string $filepath Locastion where to save the resource
* @param string $mimeType Mime type of the target file
*/
public function saveAs($filepath, $mimeType = false);
}
81 changes: 39 additions & 42 deletions src/ImageTransform/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,49 @@
*/
abstract class Image
{
/**
* @var array $attributes Key / value store to be used for meta information by delegates.
*/
protected $attributes = array();
/**
* @var array $attributes Key / value store to be used for meta information by delegates.
*/
protected array $attributes = [];

/**
* C'tor
*
* @param array $classNames List of Delegate inheriting classes providing transformations.
*/
public function __construct($filepath = false)
{
$this->initialize();

if(false !== $filepath)
/**
* @param bool $filepath
*/
public function __construct($filepath = false)
{
$this->open($filepath);
$this->initialize();

if (false !== $filepath) {
$this->open($filepath);
}
}
}

/**
* Initializes image-api specific code
*/
abstract protected function initialize();
/**
* Initializes image-api specific code
*/
abstract protected function initialize();

/**
* Attribute accessor.
*
* @param string $key Name of the attribute to return
* @param array $default Default value in case the key is unknown
* @return mixed The value as stored in $this->attributes[$key] or the $default
*/
public function get($key, $default = false)
{
return array_key_exists($key, $this->attributes) ? $this->attributes[$key] : $default;
}
/**
* Attribute accessor.
*
* @param string $key Name of the attribute to return
* @param bool|array $default Default value in case the key is unknown
* @return mixed The value as stored in $this->attributes[$key] or the $default
*/
public function get(string $key, bool|array $default = false): mixed
{
return array_key_exists($key, $this->attributes) ? $this->attributes[$key] : $default;
}

/**
* Attribute mutator.
w
*
* @param string $key Name of the attribute to set
* @param array $value Value to be set
*/
public function set($key, $value)
{
$this->attributes[$key] = $value;
}
/**
* Attribute mutator.
* w
*
* @param string $key Name of the attribute to set
* @param array $value Value to be set
*/
public function set($key, $value): void
{
$this->attributes[$key] = $value;
}
}
Loading