public image ( string $fileName = null, string | integer $width = null, string | integer $height = null, string $crop = null ) : string | ||
$fileName | string | Target filename |
$width | string | integer | Target width |
$height | string | integer | Target height |
$crop | string | String identifier for cropped images |
return | string | Image path |
public function image($fileName = null, $width = null, $height = null, $crop = null)
{
//Check if it's an alias as the only parameter after $filename
if ($width && !$height && !$crop && $this->isAlias($width)) {
return $this->getAliasedUri($filename, $width);
}
if ($width || $height) {
// You don't want the image, you just want a thumbnail.
return $this->thumbnail($fileName, $width, $height, $crop);
}
// After v1.5.1 we store image data as an array
if (is_array($fileName)) {
$fileName = isset($fileName['filename']) ? $fileName['filename'] : (isset($fileName['file']) ? $fileName['file'] : '');
}
if (!$fileName) {
return null;
}
$file = $this->app['filesystem.matcher']->getFile($fileName);
$url = $file->url();
return $url;
}
public function testImageFileNameCrop() { $app = $this->getApp(); $handler = new ImageHandler($app); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'f'); $this->assertSame('/thumbs/20x20f/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'fit'); $this->assertSame('/thumbs/20x20f/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'r'); $this->assertSame('/thumbs/20x20r/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'resize'); $this->assertSame('/thumbs/20x20r/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'b'); $this->assertSame('/thumbs/20x20b/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'borders'); $this->assertSame('/thumbs/20x20b/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'c'); $this->assertSame('/thumbs/20x20c/generic-logo.png', $result); $result = $handler->image(['filename' => 'generic-logo.png'], 20, 20, 'crop'); $this->assertSame('/thumbs/20x20c/generic-logo.png', $result); }