Skip to content

Commit

Permalink
Merge branch 'bnomei-php8'
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Feb 27, 2023
2 parents 82dbef9 + b25f03d commit 755615d
Show file tree
Hide file tree
Showing 14 changed files with 2,675 additions and 2,185 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = true

[*]
indent_style = space
indent_size = 2
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/examples export-ignore
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# System files
# ------------
.DS_Store
test/

# Editors
# (sensitive workspace files)
# ---------------------------
*.sublime-project
*.sublime-workspace
/.vscode
/.idea
/.nova

vendor/
91 changes: 78 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ try {

## Requirements

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

## Features

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

### Savers

#### `toDataUri($mimeType, $quality)`
#### `toDataUri($mimeType, $options)`

Generates a data URI.

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

Returns a string containing a data URI.

#### `toDownload($filename, $mimeType, $quality)`
#### `toDownload($filename, $mimeType, $options)`

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

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

Returns a SimpleImage object.

#### `toFile($file, $mimeType, $quality)`
#### `toFile($file, $mimeType, $options)`

Writes the image to a file.

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

Returns a SimpleImage object.

#### `toScreen($mimeType, $quality)`
#### `toScreen($mimeType, $options)`

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

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

Returns a SimpleImage object.

#### `toString($mimeType, $quality)`
#### `toString($mimeType, $options)`

Generates an image string.

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

Returns a SimpleImage object.

#### Options array

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.

```php
$image->toFile($file, 'image/avif', [
// JPG, WEBP, AVIF (default 100)
'quality' => 100,

// AVIF (default -1 which is 6)
// range of slow and small file 0 to 10 fast but big file
'speed' => -1,
]);
```

```php
$image->toFile($file, 'image/bmp', [
// BMP: boolean (default true)
'compression' => true,

// BMP, JPG (default null, keep the same)
'interlace' => null,
]);
```

```php
$image->toFile($file, 'image/gif', [
// GIF, PNG (default true)
'alpha' => true,
]);
```

```php
$image->toFile($file, 'image/jpeg', [
// BMP, JPG (default null, keep the same)
'interlace' => null,

// JPG, WEBP, AVIF (default 100)
'quality' => 100,
]);
```

```php
$image->toFile($file, 'image/png', [
// GIF, PNG (default true)
'alpha' => true,

// PNG: 0-10, defaults to zlib (default 6)
'compression' => -1,

// PNG (default -1)
'filters' => -1,

// has no effect on PNG images, since the format is lossless
// 'quality' => 100,
]);
```

```php
$image->toFile($file, 'image/webp', [
// JPG, WEBP, AVIF (default 100)
'quality' => 100,
]);
```

### Utilities

#### `getAspectRatio()`
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "A PHP class that makes working with images as simple as possible.",
"license": "MIT",
"require": {
"php": ">=5.6.0",
"php": ">=8.0",
"ext-gd": "*",
"league/color-extractor": "0.3.*"
"league/color-extractor": "0.4.*"
},
"authors": [
{
Expand All @@ -18,5 +18,9 @@
"psr-0": {
"claviska": "src/"
}
},
"require-dev": {
"laravel/pint": "^1.5",
"phpstan/phpstan": "^1.10"
}
}
Loading

0 comments on commit 755615d

Please sign in to comment.