Skip to content

Commit 755615d

Browse files
committed
Merge branch 'bnomei-php8'
2 parents 82dbef9 + b25f03d commit 755615d

14 files changed

+2675
-2185
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = true
22

33
[*]
44
indent_style = space
5-
indent_size = 2
5+
indent_size = 4
66
end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true

.gitattributes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/examples export-ignore
2+
/.github export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore

.gitignore

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
# System files
2+
# ------------
13
.DS_Store
2-
test/
4+
5+
# Editors
6+
# (sensitive workspace files)
7+
# ---------------------------
8+
*.sublime-project
9+
*.sublime-workspace
10+
/.vscode
11+
/.idea
12+
/.nova
13+
14+
vendor/

README.md

+78-13
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ try {
3737

3838
## Requirements
3939

40-
- PHP 5.6+
40+
- PHP 8.0+
4141
- [GD extension](http://php.net/manual/en/book.image.php)
4242

4343
## Features
4444

45-
- Supports reading, writing, and converting GIF, JPEG, PNG, WEBP, BMP formats.
45+
- Supports reading, writing, and converting GIF, JPEG, PNG, WEBP, BMP, AVIF formats.
4646
- Reads and writes files, data URIs, and image strings.
4747
- Manipulation: crop, resize, overlay/watermark, adding TTF text
4848
- Drawing: arc, border, dot, ellipse, line, polygon, rectangle, rounded rectangle
4949
- Filters: blur, brighten, colorize, contrast, darken, desaturate, edge detect, emboss, invert, opacity, pixelate, sepia, sharpen, sketch
5050
- Utilities: color adjustment, darken/lighten color, extract colors
5151
- Properties: exif data, height/width, mime type, orientation
5252
- Color arguments can be passed in as any CSS color (e.g. `LightBlue`), a hex color, or an RGB(A) array.
53-
- Support for alpha-transparency (GIF, PNG, WEBP)
53+
- Support for alpha-transparency (GIF, PNG, WEBP, AVIF)
5454
- Chainable methods
5555
- Uses exceptions
5656
- Load with Composer or manually (just one file)
@@ -141,52 +141,117 @@ Returns a SimpleImage object.
141141

142142
### Savers
143143

144-
#### `toDataUri($mimeType, $quality)`
144+
#### `toDataUri($mimeType, $options)`
145145

146146
Generates a data URI.
147147

148148
- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).
149-
- `$quality` (int) - Image quality as a percentage (default 100). This argument has no effect on PNG images, since the format is lossless.
149+
- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).
150150

151151
Returns a string containing a data URI.
152152

153-
#### `toDownload($filename, $mimeType, $quality)`
153+
#### `toDownload($filename, $mimeType, $options)`
154154

155155
Forces the image to be downloaded to the clients machine. Must be called before any output is sent to the screen.
156156

157157
- `$filename`* (string) - The filename (without path) to send to the client (e.g. 'image.jpeg').
158158
- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).
159-
- `$quality` (int) - Image quality as a percentage (default 100). This argument has no effect on PNG images, since the format is lossless.
159+
- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).
160160

161161
Returns a SimpleImage object.
162162

163-
#### `toFile($file, $mimeType, $quality)`
163+
#### `toFile($file, $mimeType, $options)`
164164

165165
Writes the image to a file.
166166

167167
- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).
168-
- `$quality` (int) - Image quality as a percentage (default 100). This argument has no effect on PNG images, since the format is lossless.
168+
- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).
169169

170170
Returns a SimpleImage object.
171171

172-
#### `toScreen($mimeType, $quality)`
172+
#### `toScreen($mimeType, $options)`
173173

174174
Outputs the image to the screen. Must be called before any output is sent to the screen.
175175

176176
- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).
177-
- `$quality` (int) - Image quality as a percentage (default 100). This argument has no effect on PNG images, since the format is lossless.
177+
- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).
178178

179179
Returns a SimpleImage object.
180180

181-
#### `toString($mimeType, $quality)`
181+
#### `toString($mimeType, $options)`
182182

183183
Generates an image string.
184184

185185
- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).
186-
- `$quality` (int) - Image quality as a percentage (default 100). This argument has no effect on PNG images, since the format is lossless.
186+
- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).
187187

188188
Returns a SimpleImage object.
189189

190+
#### Options array
191+
192+
Instead of providing the quality as an integer as the last function parameter you can also set various options depending on the targeted Mime type using an associative array.
193+
194+
```php
195+
$image->toFile($file, 'image/avif', [
196+
// JPG, WEBP, AVIF (default 100)
197+
'quality' => 100,
198+
199+
// AVIF (default -1 which is 6)
200+
// range of slow and small file 0 to 10 fast but big file
201+
'speed' => -1,
202+
]);
203+
```
204+
205+
```php
206+
$image->toFile($file, 'image/bmp', [
207+
// BMP: boolean (default true)
208+
'compression' => true,
209+
210+
// BMP, JPG (default null, keep the same)
211+
'interlace' => null,
212+
]);
213+
```
214+
215+
```php
216+
$image->toFile($file, 'image/gif', [
217+
// GIF, PNG (default true)
218+
'alpha' => true,
219+
]);
220+
```
221+
222+
```php
223+
$image->toFile($file, 'image/jpeg', [
224+
// BMP, JPG (default null, keep the same)
225+
'interlace' => null,
226+
227+
// JPG, WEBP, AVIF (default 100)
228+
'quality' => 100,
229+
]);
230+
```
231+
232+
```php
233+
$image->toFile($file, 'image/png', [
234+
// GIF, PNG (default true)
235+
'alpha' => true,
236+
237+
// PNG: 0-10, defaults to zlib (default 6)
238+
'compression' => -1,
239+
240+
// PNG (default -1)
241+
'filters' => -1,
242+
243+
// has no effect on PNG images, since the format is lossless
244+
// 'quality' => 100,
245+
]);
246+
```
247+
248+
```php
249+
$image->toFile($file, 'image/webp', [
250+
// JPG, WEBP, AVIF (default 100)
251+
'quality' => 100,
252+
]);
253+
```
254+
190255
### Utilities
191256

192257
#### `getAspectRatio()`

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"description": "A PHP class that makes working with images as simple as possible.",
44
"license": "MIT",
55
"require": {
6-
"php": ">=5.6.0",
6+
"php": ">=8.0",
77
"ext-gd": "*",
8-
"league/color-extractor": "0.3.*"
8+
"league/color-extractor": "0.4.*"
99
},
1010
"authors": [
1111
{
@@ -18,5 +18,9 @@
1818
"psr-0": {
1919
"claviska": "src/"
2020
}
21+
},
22+
"require-dev": {
23+
"laravel/pint": "^1.5",
24+
"phpstan/phpstan": "^1.10"
2125
}
2226
}

0 commit comments

Comments
 (0)