Skip to content

Commit

Permalink
issue-flyimg#169: Output auto problem, closes flyimg#169
Browse files Browse the repository at this point in the history
  • Loading branch information
sadok-f committed Aug 2, 2018
1 parent 96ceefa commit de6b27c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Core/Entity/Image/OutputImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function generateFileExtension()
$requestedOutput = $this->extractKey('output');

if ($requestedOutput == self::EXT_INPUT) {
$resolvedExtension = $this->inputImageExtension();
$resolvedExtension = $this->extensionByMimeType($this->inputImage->sourceImageMimeType());
} elseif ($requestedOutput == self::EXT_AUTO) {
$resolvedExtension = $this->autoExtension();
} else {
Expand Down Expand Up @@ -198,17 +198,26 @@ protected function autoExtension(): string
return self::EXT_WEBP;
}

return $this->extensionByMimeType($this->inputImage->sourceImageMimeType());
}

/**
* given a mime-type this returns the extension associated to it
*
* @param string $mimeType mime-type
*
* @return string extension OR jpeg as default
*/
protected function extensionByMimeType(string $mimeType): string
{
$mimeToExtensions = [
self::PNG_MIME_TYPE => self::EXT_PNG,
self::WEBP_MIME_TYPE => self::EXT_WEBP,
self::JPEG_MIME_TYPE => self::EXT_JPG,
self::GIF_MIME_TYPE => self::EXT_GIF,
];

return array_key_exists(
$this->inputImage->sourceImageMimeType(),
$mimeToExtensions
) ? $mimeToExtensions[$this->inputImage->sourceImageMimeType()] : self::EXT_JPG;
return array_key_exists($mimeType, $mimeToExtensions) ? $mimeToExtensions[$mimeType] : self::EXT_JPG;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Entity/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function __construct($imageHandler, $filePathResolver, $maxAge)
protected function generateHeaders(OutputImage $image)
{
$this->headers->set('Content-Type', $this->imageHandler->responseContentType($image));
$this->headers->set('Content-Disposition', sprintf('inline;filename="%s"', $image->getOutputImageName()));


$expireDate = new \DateTime();
$expireDate->add(new \DateInterval('P1Y'));
Expand Down

0 comments on commit de6b27c

Please sign in to comment.