Image
class Image implements Responsable, Stringable
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected ImageSource | $source | The original image source. |
|
| protected ImagePipeline | $pipeline | The image processing pipeline. |
|
| protected string|null | $driver | The driver override. |
|
| protected string|null | $processedContents | The processed image contents. |
|
| protected string|null | $mimeType | The cached MIME type. |
|
| protected null|array{0: int, 1: int} | $dimensions | The cached image dimensions. |
|
| protected string|null | $dominantColor | The cached dominant color. |
|
| protected string|null | $hashName | The cached hash name. |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Crop the image to the given dimensions and position.
Resize the image to the given dimensions.
Rotate the image clockwise by the given angle.
Ensure the image dimensions are valid.
Flip the image vertically.
Flip the image horizontally.
Set the optimization options.
Ensure the value is within the given range.
Store the processed image on a filesystem disk.
Store the processed image on a filesystem disk with public visibility.
Store the processed image on a filesystem disk with a given name.
Store the processed image on a filesystem disk with public visibility and a given name.
Get a hashed filename with the correct extension.
Process the image and return the raw bytes.
Process the image recipe.
Process the image and return as a base64 encoded string.
Process the image and return as a data URI.
Get the file extension based on the MIME type.
Get the MIME type of the processed image.
Get the dimensions of the processed image.
Get the width of the processed image.
Get the height of the processed image.
Get the dominant (average) color of the image as a hex string.
Use the Imagick driver for processing.
Resolve the image processing driver.
Get the underlying uploaded file instance.
Clone the pipeline and reset all derived state.
Prevent serialization of the image.
Get the string representation of the image.
Get the string representation of the image.
Flush all static state.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 87
__construct(Closure|string $contents, UploadedFile|null $file = null)
Create a new image instance.
at line 103
Image
cover(int $width, int $height)
Set the cover dimensions.
at line 118
Image
contain(int $width, int $height, string|null $background = null)
Set the contain dimensions.
at line 133
Image
crop(int $width, int $height, int $x = 0, int $y = 0)
Crop the image to the given dimensions and position.
at line 148
Image
resize(int|null $width = null, int|null $height = null)
Resize the image to the given dimensions.
at line 162
Image
rotate(float $angle, string|null $background = null)
Rotate the image clockwise by the given angle.
at line 175
Image
scale(int|null $width = null, int|null $height = null)
Set the scale dimensions.
at line 191
protected void
ensureValidDimensions(int|null $width, int|null $height)
Ensure the image dimensions are valid.
at line 205
Image
orient()
Auto-orient the image based on EXIF data.
at line 217
Image
blur(int $amount = 5)
Apply a blur effect.
at line 227
Image
grayscale()
Convert the image to grayscale.
at line 239
Image
sharpen(int $amount = 10)
Sharpen the image.
at line 249
Image
flipVertically()
Flip the image vertically.
at line 257
Image
flipHorizontally()
Flip the image horizontally.
at line 265
Image
flip()
Flip the image vertically.
at line 273
Image
flop()
Flip the image horizontally.
at line 281
Image
transform(Transformation $transformation)
Add a transformation to the image pipeline.
at line 293
Image
optimize(string $format = 'webp', int $quality = ImageOutputOptions::DEFAULT_QUALITY)
Set the optimization options.
at line 305
Image
quality(int $quality)
Set the output quality.
at line 317
protected void
ensureValueIsBetween(string $name, int $value, int $minimum, int $maximum)
Ensure the value is within the given range.
at line 327
Image
toWebp()
Convert the image to WebP format.
at line 335
Image
toJpg()
Convert the image to JPEG format.
at line 343
Image
toJpeg()
Convert the image to JPEG format.
at line 351
Image
toPng()
Convert the image to PNG format.
at line 359
Image
toGif()
Convert the image to GIF format.
at line 367
Image
toAvif()
Convert the image to AVIF format.
at line 375
Image
toHeic()
Convert the image to HEIC format.
at line 383
Image
toJxl()
Convert the image to JPEG XL format.
at line 391
Image
toBmp()
Convert the image to BMP format.
at line 401
Image
toFormat(string $format)
Set the output format.
at line 417
string|false
store(string $path = '', UnitEnum|string|null $disk = null, array $options = [])
Store the processed image on a filesystem disk.
at line 427
string|false
storePublicly(string $path = '', UnitEnum|string|null $disk = null, array $options = [])
Store the processed image on a filesystem disk with public visibility.
at line 439
string|false
storeAs(string $path, string|null $name = null, UnitEnum|string|null $disk = null, array $options = [])
Store the processed image on a filesystem disk with a given name.
at line 459
string|false
storePubliclyAs(string $path, string|null $name = null, UnitEnum|string|null $disk = null, array $options = [])
Store the processed image on a filesystem disk with public visibility and a given name.
at line 473
string
hashName(string $path = '')
Get a hashed filename with the correct extension.
at line 485
string
toBytes()
Process the image and return the raw bytes.
at line 499
protected string
process()
Process the image recipe.
at line 517
string
toBase64()
Process the image and return as a base64 encoded string.
at line 525
string
toDataUri()
Process the image and return as a data URI.
at line 533
string
extension()
Get the file extension based on the MIME type.
at line 553
string
mimeType()
Get the MIME type of the processed image.
at line 565
array
dimensions()
Get the dimensions of the processed image.
at line 603
int
width()
Get the width of the processed image.
at line 611
int
height()
Get the height of the processed image.
at line 619
string
dominantColor()
Get the dominant (average) color of the image as a hex string.
at line 627
Image
using(string $driver)
Set the driver to use for processing.
at line 639
Image
usingGd()
Use the GD driver for processing.
at line 647
Image
usingImagick()
Use the Imagick driver for processing.
at line 655
protected Driver
resolveDriver()
Resolve the image processing driver.
at line 668
UploadedFile|null
file()
Get the underlying uploaded file instance.
at line 676
void
__clone()
Clone the pipeline and reset all derived state.
at line 689
protected Image
newClone()
Create an immutable clone with copied options.
at line 697
protected Image
withOutput(Closure $callback)
Create an immutable clone with updated output options.
at line 705
protected Image
withClone(Closure $callback)
Create an immutable clone with the given callback applied.
at line 717
Response
toResponse(Request $request)
Create an HTTP response that represents the image.
at line 729
never
__serialize()
Prevent serialization of the image.
at line 737
string
toString()
Get the string representation of the image.
at line 745
string
__toString()
Get the string representation of the image.
at line 753
static void
flushState()
Flush all static state.