Responses
In addition to generating manipulated images, Glide also helps with creating HTTP responses using the getImageResponse()
method. This is recommended over the outputImage()
method, since it allows your application to handle the actual output of the image.
However, the type of response object needed depends on your application or framework. For example, you may want a PSR-7 response object if you’re using the Slim framework. Or, if you’re using Laravel or Symfony, you may want to use an HttpFoundation object. To use the getImageResponse()
method you must configure Glide to return the response you want.
Response integrations
Vendor | Message interface | Adapter package |
---|---|---|
PSR-7 | PSR-7 | Included in base package |
CakePHP | Vendor specific | league/glide-cake |
Laravel | HttpFoundation | league/glide-laravel |
Slim | PSR-7 | league/glide-slim |
Symfony | HttpFoundation | league/glide-symfony |
Zend | PSR-7 | league/glide-zend |
Custom responses
If your particular project doesn’t use PSR-7 or HttpFoundation, or if you’d like finer control over how your response objects are created, you can use your own response factories. Glide provides the ResponseFactoryInterface
interface for this.
<?php
namespace League\Glide\Responses;
use League\Flysystem\FilesystemOperator;
interface ResponseFactoryInterface
{
/**
* Create the response.
* @param FilesystemOperator $cache The cache file system.
* @param string $path The cached file path.
* @return mixed The response object.
*/
public function create(FilesystemOperator $cache, $path);
}