Skip to content

Commit

Permalink
fixed #14 and set content-type header
Browse files Browse the repository at this point in the history
  • Loading branch information
ojhaujjwal committed Aug 24, 2014
1 parent f60f2d4 commit 6f071c8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Imagine/Loader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileSystemLoader implements LoaderInterface
public function __construct(ResolverInterface $resolver)
{
$this->resolver = $resolver;
$this->loader = new SimpleFileSystemLoader('');
$this->loader = new SimpleFileSystemLoader(null);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Imagine/Loader/SimpleFileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public function load($path)
);
}

$absolutePath = $this->rootPath . '/' . ltrim($path, '/');
if ($this->rootPath === null) {
$absolutePath = $path;
} else {
$absolutePath = $this->rootPath . '/' . ltrim($path, '/');
}

if (!file_exists($absolutePath)) {
throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $absolutePath));
Expand Down
28 changes: 28 additions & 0 deletions src/View/Strategy/ImageStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ public function injectResponse(ViewEvent $e)

$response = $e->getResponse();
$response->setContent($result);

$response->getHeaders()->addHeaderLine('Content-type', $this->getMimeType($model->getFormat()));
}
}

/**
* Internal
*
* Get the mime type based on format.
*
* @param string $format
*
* @return string mime-type
*
* @throws RuntimeException
*/
protected function getMimeType($format)
{
static $mimeTypes = array(
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'pjpeg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'wbmp' => 'image/vnd.wap.wbmp',
'xbm' => 'image/xbm',
);

return $mimeTypes[$format];
}
}

0 comments on commit 6f071c8

Please sign in to comment.