The Streams platform comes with a fluid and highly extensible image handling and manipulation tool that leans heavily on the fantastic Intervention Image.
To get started, use the Images
facade to create a new image for working with.
use Streams\Core\Support\Facades\Images;
$image = Images::make('img/foo.jpg');
The facade is aliased for use in views as well:
@verbatim{!! Images::make('resources/img/foo.jpg') !!}@endverbatim
The first and only argument should be the source image to display. The following sources are supported out of the box:
Any image path relative to the application root may be used.
@verbatim{!! Images::make('resources/img/foo.jpg') !!}@endverbatim
You may use any configured storage location as an image source.
@verbatim{!! Images::make('public://img/foo.jpg') !!}@endverbatim
If the file is not found relative to the base path of your application, the default public disk will be attempted.
@verbatim{!! Images::make('img/foo.jpg') !!}@endverbatim
The URL of a remote image may also be used. The allow_url_fopen
PHP directive must be enabled to use remote image sources.
@verbatim{!! Images::make('https://example.com/img/foo.jpg') !!}@endverbatim
Remote images are cached locally. To use remote images without caching locally just use regular <img>
tags.
Use named images to register image variables:
You may regiter iamges by name using the register method:
use Streams\Core\Support\Facades\Images;
Images::register('logo.jpg', 'images/logo.jpg');
@verbatim{!! Images::make('logo.jpg')->fit(300, 500)->quality(60) !!}@endverbatim
After you initiat a new image instance with Images::make()
, you can use the below manipulation methods.
Chain methods together for more comple manipulations.
use Streams\Core\Support\Facades\Images;
$image = Images::make('img/foo.jpg')
->fit(300, 500)
->quality(60)
->orientate();
@verbatim{!! Images::make('resources/img/foo.jpg')
->fit(300, 500)
->quality(60)
->orientate() !!}@endverbatim
Use the following methods to resize images.
Use the following methods to adjust various aspects of images.
Additionally, you may use the quality
method to adjust the quality alone of JPG images.
Images::make('img/foo.jpg')->quality(60);
Use the following methods to apply effects to images.
Use the following methods to draw on images.
Macros are a basic method of extending the Streams platform.
You can define macros in a service provider.
use Streams\Core\Image\Image;
Image::macro('thumbnail', function () {
return $this->fit(148)->encode('jpg', 50);
});
$thumbnail = Images::make('img/foo.jpg')->thumbnail();
Use output methods to display image data from an image object. The img
method is used by default.
Use the img
method to return an <img>
tag.
@verbatim{!! Images::make('img/foo.jpg') !!}@endverbatim
The first parameter can be an alt
tag or array of attributes. If an alt tag is provided, the attributes can still be provided as a second parameter. Note this is the default output method when used in Blade.
Images::make('img/foo.jpg')->img('Foo Bar Image', ['width' => '100'])
Note that unmatched methods will pass through to set attribute values.
Images::make('img/foo.jpg')->width(100)->img('Foo Bar Image')
Use the url
method to output a URL to the image. The first argument may be an array of query string parameters to append. The second argument can be used to force secure URLs. If not specified, the URLs will use the protocol of the request. If
Images::make('img/foo.jpg')->url()
// Append a manual version query parameter.
Images::make('img/foo.jpg')->url(['version' => 'v1'])
Use the inline
method to return an <img>
tag with a base64 encoded src.
@verbatim{!! Images::inline('img/foo.jpg') !!}@endverbatim
The first parameter can be an alt
tag or array of attributes. If an alt tag is provided, the attributes can still be provided as a second parameter. Note this is the default output method when used in Blade.
Images::make('img/foo.jpg')->inline('Foo Bar')
Use the base64
method to return a base64 encoded string.
@verbatim<img src="{!! Images::make('img/foo.jpg')->base64() !!}">@endverbatim
Use the css
method to return a url()
string for use in CSS backgrounds.
@verbatim<div style="background: {!! Images::make('img/foo.jpg')->css() !!};">@endverbatim
The data
method will return the contents of the image as a string.
echo Images::make('img/foo.jpg')->data()
Images::make('img/foo.jpg')
->srcsets([
'1x' => [
'resize' => 400,
'quality' => 60
],
'2x' => [
'resize' => 800,
'quality' => 90
],
'640w' => [
'resize' => 800,
'quality' => 90
]
]);
Images::make('img/foo.jpg')
->srcset([
'(min-width: 600px) 400px' => [
'intrinsic' => 400,
'resize' => 400,
'quality' => 60
],
'(min-width: 1600px) 800px' => [
'intrinsic' => 800,
'resize' => 800,
'quality' => 90
]
])->img();
Images::make('img/foo.jpg')
->resize(1800) // Fallback
->picture([
'(min-width: 600px)' => [
'resize' => 400,
'quality' => 60
],
'(min-width: 1600px)' => [
'resize' => 800,
'quality' => 90
]
]);
A blank TALL-stack Laravel project with Streams.
The fundamental features and utilities offered by the Streams platform.
A universal and extensible RESTful API for Streams.
Extensible, user-friendly, and performant control panel, components, and services.
Dev tooling for Laravel Streams.