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 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 86
__construct(Closure|string $contents, UploadedFile|null $file = null)
Create a new image instance.
at line 102
Image
cover(int $width, int $height)
Set the cover dimensions.
at line 117
Image
contain(int $width, int $height, string|null $background = null)
Set the contain dimensions.
at line 132
Image
crop(int $width, int $height, int $x = 0, int $y = 0)
Crop the image to the given dimensions and position.
at line 147
Image
resize(int|null $width = null, int|null $height = null)
Resize the image to the given dimensions.
at line 161
Image
rotate(float $angle, string|null $background = null)
Rotate the image clockwise by the given angle.
at line 174
Image
scale(int|null $width = null, int|null $height = null)
Set the scale dimensions.
at line 190
protected void
ensureValidDimensions(int|null $width, int|null $height)
Ensure the image dimensions are valid.
at line 204
Image
orient()
Auto-orient the image based on EXIF data.
at line 216
Image
blur(int $amount = 5)
Apply a blur effect.
at line 226
Image
grayscale()
Convert the image to grayscale.
at line 238
Image
sharpen(int $amount = 10)
Sharpen the image.
at line 248
Image
flipVertically()
Flip the image vertically.
at line 256
Image
flipHorizontally()
Flip the image horizontally.
at line 264
Image
flip()
Flip the image vertically.
at line 272
Image
flop()
Flip the image horizontally.
at line 280
Image
transform(Transformation $transformation)
Add a transformation to the image pipeline.
at line 292
Image
optimize(string $format = 'webp', int $quality = ImageOutputOptions::DEFAULT_QUALITY)
Set the optimization options.
at line 304
Image
quality(int $quality)
Set the output quality.
at line 316
protected void
ensureValueIsBetween(string $name, int $value, int $minimum, int $maximum)
Ensure the value is within the given range.
at line 326
Image
toWebp()
Convert the image to WebP format.
at line 334
Image
toJpg()
Convert the image to JPEG format.
at line 342
Image
toJpeg()
Convert the image to JPEG format.
at line 350
Image
toPng()
Convert the image to PNG format.
at line 358
Image
toGif()
Convert the image to GIF format.
at line 366
Image
toAvif()
Convert the image to AVIF format.
at line 374
Image
toHeic()
Convert the image to HEIC format.
at line 382
Image
toBmp()
Convert the image to BMP format.
at line 392
Image
toFormat(string $format)
Set the output format.
at line 408
string|false
store(string $path = '', UnitEnum|string|null $disk = null, array $options = [])
Store the processed image on a filesystem disk.
at line 418
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 430
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 450
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 464
string
hashName(string $path = '')
Get a hashed filename with the correct extension.
at line 476
string
toBytes()
Process the image and return the raw bytes.
at line 490
protected string
process()
Process the image recipe.
at line 504
string
toBase64()
Process the image and return as a base64 encoded string.
at line 512
string
toDataUri()
Process the image and return as a data URI.
at line 520
string
extension()
Get the file extension based on the MIME type.
at line 539
string
mimeType()
Get the MIME type of the processed image.
at line 551
array
dimensions()
Get the dimensions of the processed image.
at line 585
int
width()
Get the width of the processed image.
at line 593
int
height()
Get the height of the processed image.
at line 601
string
dominantColor()
Get the dominant (average) color of the image as a hex string.
at line 609
Image
using(string $driver)
Set the driver to use for processing.
at line 621
Image
usingGd()
Use the GD driver for processing.
at line 629
Image
usingImagick()
Use the Imagick driver for processing.
at line 637
protected Driver
resolveDriver()
Resolve the image processing driver.
at line 650
UploadedFile|null
file()
Get the underlying uploaded file instance.
at line 658
void
__clone()
Clone the pipeline and reset all derived state.
at line 671
protected Image
newClone()
Create an immutable clone with copied options.
at line 679
protected Image
withOutput(Closure $callback)
Create an immutable clone with updated output options.
at line 687
protected Image
withClone(Closure $callback)
Create an immutable clone with the given callback applied.
at line 699
Response
toResponse(Request $request)
Create an HTTP response that represents the image.
at line 711
never
__serialize()
Prevent serialization of the image.
at line 719
string
toString()
Get the string representation of the image.
at line 727
string
__toString()
Get the string representation of the image.
at line 735
static void
flushState()
Flush all static state.