Skip to content

Commit

Permalink
Merge pull request #74 from zoonru/master
Browse files Browse the repository at this point in the history
Update for php 8, phpunit 9 and switch to github actions
  • Loading branch information
jenssegers authored May 20, 2021
2 parents 71359be + a6dbd06 commit c7407cb
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: build
on:
pull_request:
push:
jobs:
run:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["7.1", "7.2", "7.3", "7.4", "8.0"]
extensions: ["gd", "imagick"]
name: PHP ${{ matrix.php-versions }} - ${{ matrix.extensions }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ matrix.extensions }}
coverage: xdebug

- name: Check environment
run: |
php --version
composer --version
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ matrix.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.os }}-composer-${{ matrix.php-versions }}-

- name: Install dependencies
run: composer install --prefer-dist

- name: Run tests
env:
PHP_CS_FIXER_IGNORE_ENV: 1
run: |
vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
- name: Upload coverage to Codecov
env:
OS: ${{ matrix.os }}
PHP: ${{ matrix.php-versions }}
uses: codecov/codecov-action@v1
with:
file: build/logs/clover.xml
env_vars: OS,PHP
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
composer.lock
.phpunit.result.cache
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.1|^8.0",
"intervention/image": "^2.4",
"phpseclib/phpseclib": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0|^7.0",
"phpunit/phpunit": "^7|^8|^9",
"php-coveralls/php-coveralls": "^2.0"
},
"suggest": {
Expand Down
12 changes: 12 additions & 0 deletions src/Implementations/BlockHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ private function uneven(Image $image): Hash
}

// Add weighted pixel value to relevant blocks.
if (!isset($blocks[$blockTop][$blockLeft])) {
$blocks[$blockTop][$blockLeft] = 0;
}
if (!isset($blocks[$blockTop][$blockRight])) {
$blocks[$blockTop][$blockRight] = 0;
}
if (!isset($blocks[$blockBottom][$blockLeft])) {
$blocks[$blockBottom][$blockLeft] = 0;
}
if (!isset($blocks[$blockBottom][$blockRight])) {
$blocks[$blockBottom][$blockRight] = 0;
}
$blocks[$blockTop][$blockLeft] += $value * $weightTop * $weightLeft;
$blocks[$blockTop][$blockRight] += $value * $weightTop * $weightRight;
$blocks[$blockBottom][$blockLeft] += $value * $weightBottom * $weightLeft;
Expand Down
15 changes: 11 additions & 4 deletions tests/CompatibilityTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Intervention\Image\ImageManager;
use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\AverageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash;
Expand Down Expand Up @@ -89,12 +90,18 @@ public function preCalculatedImageHashes()
public function testCompatibility($implementation, $path, $precalculated)
{
$implementation = new $implementation();
$hasher = new ImageHash($implementation);
foreach (['gd', 'imagick'] as $driver) {
if (!extension_loaded($driver)) {
continue;
}

$hash = $hasher->hash($path);
$hasher = new ImageHash($implementation, new ImageManager(['driver' => $driver]));

if ($precalculated !== $hash->toHex()) {
$this->addWarning(get_class($implementation) . ' generated a different hash ' . $hash->toHex() . ' instead of ' . $precalculated);
$hash = $hasher->hash($path);

if ($precalculated !== $hash->toHex()) {
$this->addWarning(\get_class($implementation)." $driver generated a different hash ".$hash->toHex().' instead of '.$precalculated);
}
}

$this->expectNotToPerformAssertions();
Expand Down
2 changes: 1 addition & 1 deletion tests/ImageHashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ImageHashTest extends TestCase
*/
private $imageHash;

public function setup()
public function setup(): void
{
$this->imageHash = new ImageHash();
}
Expand Down

0 comments on commit c7407cb

Please sign in to comment.