Fork me on GitHub

encode — Encode image


public Intervention\Image\Image encode([mixed $format, [int $quality]])

Encodes the current image in given format and given image quality.


format (optional)

Define the encoding format from one of the following formats:

By default the method will return data encoded in the type of the current image. If no image type is defined yet, data will be encoded as jpeg.

quality (optional)

Define the quality of the encoded image optionally. Data ranging from 0 (poor quality, small file) to 100 (best quality, big file). Quality is only applied if you're encoding JPG format since PNG compression is lossless and does not affect image quality. Default: 90.

Return Values

Instance of Intervention\Image\Image with attached encoded image data. Instance can be casted to string to access data.


// encode png image as jpg
$jpg = (string) Image::make('public/foo.png')->encode('jpg', 75);

// encode image as data-url
$data = (string) Image::make('public/bar.png')->encode('data-url');

See also