1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-12 17:03:59 +02:00

rewritten binary check

This commit is contained in:
Oliver Vogel
2014-04-09 16:47:44 +02:00
parent 6c0574ddba
commit cedb085cdc
2 changed files with 18 additions and 11 deletions

View File

@@ -102,16 +102,16 @@ class Image
// image properties come from gd image resource
$this->initFromResource($source);
} elseif ($this->isBinary($source)) {
// image properties come from binary image string
$this->initFromString($source);
} elseif (filter_var($source, FILTER_VALIDATE_URL)) {
// image will be fetched from url before init
$this->initFromString(file_get_contents($source));
} elseif ($this->isBinary($source)) {
// image properties come from binary image string
$this->initFromString($source);
} else {
// image properties come from image file
@@ -1791,18 +1791,15 @@ class Image
}
/**
* Checks if string contains printable characters
* Checks if string contains binary image data
*
* @param mixed $input
* @return boolean
*/
private function isBinary($input)
{
if (is_resource($input)) {
return false;
}
return ( ! ctype_print($input));
$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), (string) $input);
return substr($mime, 0, 4) != 'text';
}
/**

View File

@@ -64,6 +64,16 @@ class ImageTest extends PHPUnit_Framework_Testcase
$img = new Image('public/foo/bar/invalid_image_path.jpg');
}
/**
* @expectedException Intervention\Image\Exception\ImageNotFoundException
*/
public function testConstructorWithNonAsciiCharacters()
{
// file does not exists but path string should NOT be considered
// as binary data. (should _NOT_ throw InvalidImageDataStringException)
$img = new Image('public/Über.jpg');
}
/**
* @expectedException Intervention\Image\Exception\InvalidImageTypeException
*/