Skip to content

Commit

Permalink
Merge branch 'pullrequests/Gregwar/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 25, 2024
2 parents a6a36c2 + cf21cce commit d32ba86
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 143 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PHP Tests

on: [push, pull_request]

jobs:

build:
strategy:
matrix:
operating-system: [ubuntu-22.04]
php-versions: ['7.3', '7.4', '8.0', '8.1']
fail-fast: false
runs-on: ${{ matrix.operating-system }}
steps:
- uses: actions/checkout@v3

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

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: composer run-script test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ vendor
composer.lock
/phpunit.xml
/.php_cs.cache
.idea
.phpunit.result.cache
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

9 changes: 5 additions & 4 deletions Adapter/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gregwar\Image\Image;
use Gregwar\Image\ImageColor;
use Gregwar\Image\Utils\FileUtils;

class GD extends Common
{
Expand Down Expand Up @@ -644,7 +645,7 @@ public function saveJpeg($file, $quality)
*/
protected function openJpeg($file)
{
if (file_exists($file) && filesize($file)) {
if (FileUtils::safeExists($file) && filesize($file)) {
$this->resource = @imagecreatefromjpeg($file);
} else {
$this->resource = false;
Expand All @@ -660,7 +661,7 @@ protected function openJpeg($file)
*/
protected function openGif($file)
{
if (file_exists($file) && filesize($file)) {
if (FileUtils::safeExists($file) && filesize($file)) {
$this->resource = @imagecreatefromgif($file);
} else {
$this->resource = false;
Expand All @@ -676,7 +677,7 @@ protected function openGif($file)
*/
protected function openPng($file)
{
if (file_exists($file) && filesize($file)) {
if (FileUtils::safeExists($file) && filesize($file)) {
$this->resource = @imagecreatefrompng($file);
} else {
$this->resource = false;
Expand All @@ -692,7 +693,7 @@ protected function openPng($file)
*/
protected function openWebp($file)
{
if (file_exists($file) && filesize($file)) {
if (FileUtils::safeExists($file) && filesize($file)) {
$this->resource = @imagecreatefromwebp($file);
} else {
$this->resource = false;
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gregwar's Image class

[![Build status](https://travis-ci.org/Gregwar/Image.svg?branch=master)](https://travis-ci.org/Gregwar/Image)
[![Build status](https://github.com/Gregwar/Image/actions/workflows/test.yml/badge.svg)](https://github.com/Gregwar/Image/actions/workflows/test.yml)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YUXRLWHQSWS6L)

The `Gregwar\Image` class purpose is to provide a simple object-oriented images handling and caching API.
Expand Down Expand Up @@ -211,8 +211,8 @@ You can also create your own image on-the-fly using drawing functions:

## Using fallback image

If the image file doesn't exists, you can configurate a fallback image that will be used
by the class (note that this require the cache directory to be available).
If the image file doesn't exist, you can configure a fallback image that will be used
by the class (note that this requires the cache directory to be available).

A default "error" image which is used is in `images/error.jpg`, you can change it with:

Expand Down
3 changes: 2 additions & 1 deletion Source/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gregwar\Image\Source;

use Gregwar\Image\Image;
use Gregwar\Image\Utils\FileUtils;

/**
* Open an image from a file.
Expand Down Expand Up @@ -47,7 +48,7 @@ public function correct()
*/
public function guessType()
{
if (function_exists('exif_imagetype')) {
if (function_exists('exif_imagetype') && FileUtils::safeExists($this->file)) {
$type = @exif_imagetype($this->file);

if (false !== $type) {
Expand Down
22 changes: 22 additions & 0 deletions Utils/FileUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Gregwar\Image\Utils;

class FileUtils
{
/**
* Checks that the file exists and is not a phar archive
*/
public static function safeExists($file)
{
return file_exists($file) && !self::isPhar($file);
}

/**
* Checks if the file is a phar archive
*/
public static function isPhar($file)
{
return substr(strtolower(trim($file)), 0, 7) === 'phar://';
}
}
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "getgrav/image",
"description": "Image handling",
"keywords": ["image", "gd"],
"keywords": [
"image",
"gd"
],
"homepage": "https://github.com/Gregwar/Image",
"license": "MIT",
"authors": [
Expand All @@ -17,13 +20,13 @@
}
],
"require": {
"php": "^5.6 || ^7.0 || ^8.0",
"php": "^7.2 || ^8.0",
"ext-gd": "*",
"getgrav/cache": "^2.0"
},
"require-dev": {
"sllh/php-cs-fixer-styleci-bridge": "~1.0",
"symfony/phpunit-bridge": "^2.7.4 || ^3.0"
"phpunit/phpunit": "^9"
},
"suggest": {
"behat/transliterator": "Transliterator provides ability to set non-latin1 pretty names"
Expand All @@ -33,5 +36,8 @@
"psr-0": {
"Gregwar\\Image": ""
}
},
"scripts": {
"test": "./vendor/bin/phpunit --version && ./vendor/bin/phpunit -c phpunit.xml.dist"
}
}
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
Expand Down
Loading

0 comments on commit d32ba86

Please sign in to comment.