class Image implements Stringable (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected $pipeline

The image processing pipeline.

protected $driver

The driver override.

protected $processed

Whether the image has been processed.

protected $hashName

The cached hash name.

Methods

$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(Closure|string $contents, UploadedFile|null $file = null)

Create a new image instance.

cover(int $width, int $height)

Set the cover dimensions.

contain(int $width, int $height, string|null $background = null)

Set the contain dimensions.

crop(int $width, int $height, int $x = 0, int $y = 0)

Crop the image to the given dimensions and position.

resize(int|null $width = null, int|null $height = null)

Resize the image to the given dimensions.

rotate(float $angle, string|null $background = null)

Rotate the image clockwise by the given angle.

scale(int|null $width = null, int|null $height = null)

Set the scale dimensions.

orient()

Auto-orient the image based on EXIF data.

blur(int $amount = 5)

Apply a blur effect.

grayscale()

Convert the image to grayscale.

sharpen(int $amount = 10)

Sharpen the image.

flipVertically()

Flip the image vertically.

flipHorizontally()

Flip the image horizontally.

flip()

Flip the image vertically.

flop()

Flip the image horizontally.

transform(Transformation $transformation)

Add a transformation to the image pipeline.

optimize(string $format = 'webp', int $quality = ImageOutputOptions::DEFAULT_QUALITY)

Set the optimization options.

quality(int $quality)

Set the output quality.

toWebp()

Convert the image to WebP format.

toJpg()

Convert the image to JPEG format.

toJpeg()

Convert the image to JPEG format.

toFormat(string $format)

Set the output format.

string|false
store(string $path = '', string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk.

string|false
storePublicly(string $path = '', string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk with public visibility.

string|false
storeAs(string $path, string|null $name = null, string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk with a given name.

string|false
storePubliclyAs(string $path, string|null $name = null, string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk with public visibility and a given name.

string
hashName(string $path = '')

Get a hashed filename with the correct extension.

string
toBytes()

Process the image and return the raw bytes.

string
toBase64()

Process the image and return as a base64 encoded string.

string
toDataUri()

Process the image and return as a data URI.

string
extension()

Get the file extension based on the MIME type.

string
mimeType()

Get the MIME type of the processed image.

array
dimensions()

Get the dimensions of the processed image.

int
width()

Get the width of the processed image.

int
height()

Get the height of the processed image.

using(string $driver)

Set the driver to use for processing.

usingGd()

Use the GD driver for processing.

usingImagick()

Use the Imagick driver for processing.

resolveDriver()

Resolve the image processing driver.

UploadedFile|null
file()

Get the underlying uploaded file instance.

newClone()

Create an immutable clone with copied options.

withOutput(Closure $callback)

Create an immutable clone with updated output options.

withClone(Closure $callback)

Create an immutable clone with the given callback applied.

never
__serialize()

Prevent serialization of the image.

string
toString()

Get the string representation of the image.

string
__toString()

Get the string representation of the image.

Details

$this|TWhenReturnType when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

__construct(Closure|string $contents, UploadedFile|null $file = null)

Create a new image instance.

Parameters

Closure|string $contents
UploadedFile|null $file

Image cover(int $width, int $height)

Set the cover dimensions.

Parameters

int $width
int $height

Return Value

Image

Image contain(int $width, int $height, string|null $background = null)

Set the contain dimensions.

Parameters

int $width
int $height
string|null $background

Return Value

Image

Image crop(int $width, int $height, int $x = 0, int $y = 0)

Crop the image to the given dimensions and position.

Parameters

int $width
int $height
int $x
int $y

Return Value

Image

Image resize(int|null $width = null, int|null $height = null)

Resize the image to the given dimensions.

Parameters

int|null $width
int|null $height

Return Value

Image

Image rotate(float $angle, string|null $background = null)

Rotate the image clockwise by the given angle.

Parameters

float $angle
string|null $background

Return Value

Image

Image scale(int|null $width = null, int|null $height = null)

Set the scale dimensions.

Parameters

int|null $width
int|null $height

Return Value

Image

Image orient()

Auto-orient the image based on EXIF data.

Return Value

Image

Image blur(int $amount = 5)

Apply a blur effect.

Parameters

int $amount

Return Value

Image

Image grayscale()

Convert the image to grayscale.

Return Value

Image

Image sharpen(int $amount = 10)

Sharpen the image.

Parameters

int $amount

Return Value

Image

Image flipVertically()

Flip the image vertically.

Return Value

Image

Image flipHorizontally()

Flip the image horizontally.

Return Value

Image

Image flip()

Flip the image vertically.

Return Value

Image

Image flop()

Flip the image horizontally.

Return Value

Image

Image transform(Transformation $transformation)

Add a transformation to the image pipeline.

Parameters

Transformation $transformation

Return Value

Image

Image optimize(string $format = 'webp', int $quality = ImageOutputOptions::DEFAULT_QUALITY)

Set the optimization options.

Parameters

string $format
int $quality

Return Value

Image

Exceptions

ImageException

Image quality(int $quality)

Set the output quality.

Parameters

int $quality

Return Value

Image

Image toWebp()

Convert the image to WebP format.

Return Value

Image

Image toJpg()

Convert the image to JPEG format.

Return Value

Image

Image toJpeg()

Convert the image to JPEG format.

Return Value

Image

protected Image toFormat(string $format)

Set the output format.

Parameters

string $format

Return Value

Image

Exceptions

ImageException

string|false store(string $path = '', string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk.

Parameters

string $path
string|null $disk
array $options

Return Value

string|false

string|false storePublicly(string $path = '', string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk with public visibility.

Parameters

string $path
string|null $disk
array $options

Return Value

string|false

string|false storeAs(string $path, string|null $name = null, string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk with a given name.

Parameters

string $path
string|null $name
string|null $disk
array $options

Return Value

string|false

string|false storePubliclyAs(string $path, string|null $name = null, string|null $disk = null, array $options = [])

Store the processed image on a filesystem disk with public visibility and a given name.

Parameters

string $path
string|null $name
string|null $disk
array $options

Return Value

string|false

string hashName(string $path = '')

Get a hashed filename with the correct extension.

Parameters

string $path

Return Value

string

string toBytes()

Process the image and return the raw bytes.

Return Value

string

string toBase64()

Process the image and return as a base64 encoded string.

Return Value

string

string toDataUri()

Process the image and return as a data URI.

Return Value

string

string extension()

Get the file extension based on the MIME type.

Return Value

string

string mimeType()

Get the MIME type of the processed image.

Return Value

string

array dimensions()

Get the dimensions of the processed image.

Return Value

array

int width()

Get the width of the processed image.

Return Value

int

int height()

Get the height of the processed image.

Return Value

int

Image using(string $driver)

Set the driver to use for processing.

Parameters

string $driver

Return Value

Image

Image usingGd()

Use the GD driver for processing.

Return Value

Image

Image usingImagick()

Use the Imagick driver for processing.

Return Value

Image

protected Driver resolveDriver()

Resolve the image processing driver.

Return Value

Driver

UploadedFile|null file()

Get the underlying uploaded file instance.

Return Value

UploadedFile|null

protected Image newClone()

Create an immutable clone with copied options.

Return Value

Image

protected Image withOutput(Closure $callback)

Create an immutable clone with updated output options.

Parameters

Closure $callback

Return Value

Image

protected Image withClone(Closure $callback)

Create an immutable clone with the given callback applied.

Parameters

Closure $callback

Return Value

Image

never __serialize()

Prevent serialization of the image.

Return Value

never

Exceptions

ImageException

string toString()

Get the string representation of the image.

Return Value

string

string __toString()

Get the string representation of the image.

Return Value

string