Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Database/Attach/Resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public function save($savePath)
}

// Determine the image type from the destination file
$extension = pathinfo($savePath, PATHINFO_EXTENSION) ?: $this->extension;
$extension = $this->getExtension($savePath);

// Create and save an image based on it's extension
switch (strtolower($extension)) {
Expand Down Expand Up @@ -686,4 +686,9 @@ protected function getSizeByFit($maxWidth, $maxHeight)

return [$optimalWidth, $optimalHeight];
}

protected function getExtension($path)
{
return $this->getOption('extension') ?: (pathinfo($path, PATHINFO_EXTENSION) ?: $this->extension);
}
}
19 changes: 19 additions & 0 deletions tests/Database/Attach/ResizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,25 @@ public function testCrop10x15()
$this->assertImageSameAsFixture(__METHOD__);
}

public function testGetExtension()
{
$this->setSource(self::SRC_PORTRAIT); // gif extension
$this->createFixtureResizer();

// no extension provided in path, no extension provided in options, should return source extension.
$extension = $this->callProtectedMethod($this->resizer, 'getExtension', ['dummy']);
$this->assertEquals('gif', $extension);

// no extension provided in options, extension provided in path, should return path extension
$extension = $this->callProtectedMethod($this->resizer, 'getExtension', ['dummy.jpg']);
$this->assertEquals('jpg', $extension);

// extension provided in options and in path, should return extension from options
$this->resizer->setOptions(['extension' => 'png']);
$extension = $this->callProtectedMethod($this->resizer, 'getExtension', ['dummy.jpg']);
$this->assertEquals('png', $extension);
}

/**
* Set the source path and set the extension to match.
* @param string $source Path to the source image for the Resizer
Expand Down