Skip to content
Open
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
4 changes: 2 additions & 2 deletions Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ public function polygon(array $points, $color, $filled = false);

/**
* Flips the image.
*
*
* @param int $flipVertical
* @param int $flipHorizontal
*
*
* @return $this
*/
public function flip($flipVertical, $flipHorizontal);
Expand Down
2 changes: 1 addition & 1 deletion Adapter/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ protected function openPng($file)
*/
protected function supports($type)
{
return (imagetypes() & self::$gdTypes[$type]);
return imagetypes() & self::$gdTypes[$type];
}

protected function getColor($x, $y)
Expand Down
4 changes: 2 additions & 2 deletions Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,10 @@ public function save($file, $type = 'guess', $quality = 80)
return false;
}

return (null === $file ? ob_get_clean() : $file);
return null === $file ? ob_get_clean() : $file;
} catch (\Exception $e) {
if ($this->useFallbackImage) {
return (null === $file ? file_get_contents($this->fallback) : $this->getCacheFallback());
return null === $file ? file_get_contents($this->fallback) : $this->getCacheFallback();
} else {
throw $e;
}
Expand Down
18 changes: 18 additions & 0 deletions Source/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ public function getInfos()
{
return sha1($this->data);
}

public function guessType()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a PHP doc block.

{
if (class_exists('finfo')) {
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->buffer($this->data);
switch ($mime) {
case 'image/gif':
return 'gif';
case 'image/png':
return 'png';
default:
return 'jpeg';
}
}

return 'jpeg';
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"require-dev": {
"sllh/php-cs-fixer-styleci-bridge": "~1.0",
"symfony/phpunit-bridge": "^2.7.4"
"symfony/phpunit-bridge": "^2.7.4",
"symfony/filesystem": "^2.7.4"
},
"suggest": {
"behat/transliterator": "Transliterator provides ability to set non-latin1 pretty names"
Expand Down
21 changes: 19 additions & 2 deletions tests/ImageTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use Gregwar\Image\Image;
use Gregwar\Image\ImageColor;
use Symfony\Component\Filesystem\Filesystem;

/**
* Unit testing for Image.
*/
class ImageTests extends \PHPUnit_Framework_TestCase
class ImageTest extends \PHPUnit_Framework_TestCase
{
/**
* Testing the basic width & height.
Expand Down Expand Up @@ -112,6 +113,19 @@ public function testGuess()
$this->assertSame('gif', $image->guessType());
}

/**
* Testing type guess from image data.
*/
public function testGuessFromData()
{
$image = Image::fromData(file_get_contents(__DIR__.'/files/monalisa.gif'));
$this->assertSame('gif', $image->guessType());
$image = Image::fromData(file_get_contents(__DIR__.'/files/monalisa.png'));
$this->assertSame('png', $image->guessType());
$image = Image::fromData(file_get_contents(__DIR__.'/files/monalisa.jpg'));
$this->assertSame('jpeg', $image->guessType());
}

public function testDefaultCacheSystem()
{
$image = $this->open('monalisa.jpg');
Expand Down Expand Up @@ -447,7 +461,10 @@ protected function output($file)
public function setUp()
{
$dir = $this->output('');
`rm -rf $dir`;
$filesystem = new Filesystem();

$filesystem->remove($dir);

mkdir($dir);
mkdir($this->output('cache'));
}
Expand Down