You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-7Lines changed: 48 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,12 +22,51 @@ If using [Composer](https://getcomposer.org/), in your `composer.json` file add:
22
22
```json
23
23
{
24
24
"require": {
25
-
"gumlet/php-image-resize": "2.1.*"
25
+
"gumlet/php-image-resize": "^3.0"
26
26
}
27
27
}
28
28
```
29
29
30
-
For PHP versions >= 7.2 to 8.0, `2.0.x` version of this library should be used.
30
+
**PHP 8.1 or newer** is required (with the `gd` and `fileinfo` extensions). For older PHP versions, stay on the 2.x line:
31
+
32
+
| PHP version | Library version |
33
+
|-------------|-----------------|
34
+
| 8.1 – 8.5+ |**3.x** (`^3.0`) |
35
+
| 7.2 – 8.0 |`2.0.x`|
36
+
| 8.0 (legacy)|`2.1.x` (if you were already on it) |
37
+
38
+
### Upgrading from 2.x to 3.0
39
+
40
+
3.0 is a **major** release focused on modern PHP, static analysis, and PHP 8.5 compatibility. Behavior is largely the same; most upgrades are about types and environment.
41
+
42
+
**Requirements**
43
+
44
+
- PHP **>= 8.1** (2.x supported older PHP).
45
+
-`ext-gd` and `ext-fileinfo` (unchanged).
46
+
47
+
**Breaking / API changes**
48
+
49
+
-**Typed public API** — Methods and public properties use scalar types and `static` return types (e.g. `resize(int $width, int $height, bool $allow_enlarge = false): static`). Custom subclasses that override methods must match these signatures.
50
+
-**`ImageResize::__construct(string $filename)`** — The path must be a non-empty string. Passing `null` is a `TypeError` in PHP 8+ (previously you could pass `null` and get `ImageResizeException`). Use a real path, a `data:` URL, or `ImageResize::createFromString()` for binary data.
51
+
-**`ImageResize::createFromString(string $image_data)`** — Only accepts `string`; empty string still throws `ImageResizeException` with message `image_data must not be empty`.
52
+
-**`save()` signature** — Documented types: `string|resource|null $filename`, optional `?int $image_type`, `int|string|null $quality`, `?int $permissions`, and `array|false $exact_size` (canvas size `[width, height]`, not a boolean).
53
+
-**Class constants** — Crop/flip constants are `public const` on `ImageResize` (same names and values as before).
54
+
-**BMP output** — `imagebmp()` is called without a invalid third argument (fixes deprecation when quality was `null`).
55
+
56
+
**Fixes (compatible behavior)**
57
+
58
+
- MIME detection via `finfo` runs only when `getimagesize()` fails (no `finfo_open` on every load).
59
+
-**`chmod`** after save only runs when the destination is a **file path** string (not streams or `null` used by `output()`).
**Development / quality (library consumers unaffected unless you contribute)**
63
+
64
+
- PSR-12 via PHP-CS-Fixer (`composer cs-fix` / `cs-check`).
65
+
- PHPStan level 3 on `lib/` (`composer phpstan`).
66
+
- PHPUnit 10+ config migrated; CI runs tests on PHP 8.2–8.5 and a separate static-analysis job.
67
+
- Expanded test suite (missing file, `exact_size`, enlarge, WebP/AVIF save, gamma, filters).
68
+
69
+
See [CHANGELOG.md](CHANGELOG.md) for the full 3.0.0 release notes.
31
70
32
71
Otherwise:
33
72
@@ -221,6 +260,9 @@ If you would like to save/output in a different image type, you need to pass a (
221
260
-`IMAGETYPE_GIF`
222
261
-`IMAGETYPE_JPEG`
223
262
-`IMAGETYPE_PNG`
263
+
-`IMAGETYPE_WEBP` (when GD is built with WebP support)
264
+
-`IMAGETYPE_AVIF` (when GD is built with AVIF support)
265
+
-`IMAGETYPE_BMP`
224
266
225
267
This allows you to save in a different type to the source:
226
268
@@ -242,7 +284,7 @@ $image->resize(800, 600);
242
284
$image->save('image2.jpg');
243
285
```
244
286
245
-
By default they are set to 85and 6 respectively. See the manual entries for [`imagejpeg()`](http://www.php.net/manual/en/function.imagejpeg.php) and [`imagepng()`](http://www.php.net/manual/en/function.imagepng.php) for more info.
287
+
By default they are set to 85, 85 (WebP), 60 (AVIF), and 6 (PNG) respectively. See the manual entries for [`imagejpeg()`](http://www.php.net/manual/en/function.imagejpeg.php) and [`imagepng()`](http://www.php.net/manual/en/function.imagepng.php) for more info.
246
288
247
289
You can also pass the quality directly to the `save()`, `output()` and `getImageAsString()` methods:
248
290
@@ -303,11 +345,10 @@ ImageResize throws ImageResizeException for it's own for errors. You can catch t
303
345
It is not to be expected, but should anything go horribly wrong mid way then notice or warning Errors could be shown from the PHP GD and Image Functions (http://php.net/manual/en/ref.image.php)
0 commit comments