mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 05:52:47 +02:00
Merged in the psr2 compliant code
This commit is contained in:
@@ -167,10 +167,7 @@ class Image
|
|||||||
public static function cache(Closure $callback = null, $lifetime = null, $returnObj = false)
|
public static function cache(Closure $callback = null, $lifetime = null, $returnObj = false)
|
||||||
{
|
{
|
||||||
if (!class_exists('\Intervention\Image\ImageCache')) {
|
if (!class_exists('\Intervention\Image\ImageCache')) {
|
||||||
throw new Exception\ImageCacheNotFoundException(
|
throw new Exception('Please install package intervention/imagecache before running this function.');
|
||||||
'Please install package intervention/imagecache before
|
|
||||||
running this function.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create image and run callback
|
// Create image and run callback
|
||||||
@@ -189,9 +186,7 @@ class Image
|
|||||||
private function initFromPath($path)
|
private function initFromPath($path)
|
||||||
{
|
{
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
throw new Exception\ImageNotFoundException(
|
throw new Exception("Image file ({$path}) not found");
|
||||||
"Image file ({$path}) not found"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set file info
|
// set file info
|
||||||
@@ -220,7 +215,7 @@ class Image
|
|||||||
private function initFromResource($resource)
|
private function initFromResource($resource)
|
||||||
{
|
{
|
||||||
if (!$this->isImageResource($resource)) {
|
if (!$this->isImageResource($resource)) {
|
||||||
throw new Exception\InvalidImageResourceException;
|
throw new Exception("initFromResource expects parameter to be resource.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setImageInfoFromResource($resource);
|
$this->setImageInfoFromResource($resource);
|
||||||
@@ -352,8 +347,8 @@ class Image
|
|||||||
$width = intval($height / $this->height * $this->width);
|
$width = intval($height / $this->height * $this->width);
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($ratio && ( ! is_null($width) OR ! is_null($height))) { // If only one of width or height has been provided.
|
} elseif ($ratio && ( ! is_null($width) or ! is_null($height))) {
|
||||||
|
// If only one of width or height has been provided.
|
||||||
$width = is_null($width) ? intval($height / $this->height * $this->width) : $width;
|
$width = is_null($width) ? intval($height / $this->height * $this->width) : $width;
|
||||||
$height = is_null($height) ? intval($width / $this->width * $this->height) : $height;
|
$height = is_null($height) ? intval($width / $this->width * $this->height) : $height;
|
||||||
}
|
}
|
||||||
@@ -632,7 +627,7 @@ class Image
|
|||||||
$width = is_numeric($width) ? intval($width) : null;
|
$width = is_numeric($width) ? intval($width) : null;
|
||||||
$height = is_numeric($height) ? intval($height) : null;
|
$height = is_numeric($height) ? intval($height) : null;
|
||||||
|
|
||||||
if ( ! is_null($width) OR ! is_null($height)) {
|
if (! is_null($width) or ! is_null($height)) {
|
||||||
// if width or height are not set, define values automatically
|
// if width or height are not set, define values automatically
|
||||||
$width = is_null($width) ? $height : $width;
|
$width = is_null($width) ? $height : $width;
|
||||||
$height = is_null($height) ? $width : $height;
|
$height = is_null($height) ? $width : $height;
|
||||||
@@ -1283,7 +1278,13 @@ class Image
|
|||||||
|
|
||||||
case 'rgba':
|
case 'rgba':
|
||||||
$color = imagecolorsforindex($this->resource, $color);
|
$color = imagecolorsforindex($this->resource, $color);
|
||||||
$color = sprintf('rgba(%d, %d, %d, %.2f)', $color['red'], $color['green'], $color['blue'], $this->alpha2rgba($color['alpha']));
|
$color = sprintf(
|
||||||
|
'rgba(%d, %d, %d, %.2f)',
|
||||||
|
$color['red'],
|
||||||
|
$color['green'],
|
||||||
|
$color['blue'],
|
||||||
|
$this->alpha2rgba($color['alpha'])
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'hex':
|
case 'hex':
|
||||||
@@ -1345,21 +1346,27 @@ class Image
|
|||||||
} elseif (is_string($value)) {
|
} elseif (is_string($value)) {
|
||||||
|
|
||||||
// parse color string in hexidecimal format like #cccccc or cccccc or ccc
|
// parse color string in hexidecimal format like #cccccc or cccccc or ccc
|
||||||
if (preg_match('/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i', $value, $matches)) {
|
$hexPattern = '/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i';
|
||||||
|
|
||||||
|
// parse color string in format rgb(140, 140, 140)
|
||||||
|
$rgbPattern = '/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i';
|
||||||
|
|
||||||
|
// parse color string in format rgba(255, 0, 0, 0.5)
|
||||||
|
$rgbaPattern = '/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,4})\)$/i';
|
||||||
|
|
||||||
|
if (preg_match($hexPattern, $value, $matches)) {
|
||||||
|
|
||||||
$r = strlen($matches[1]) == '1' ? '0x'.$matches[1].$matches[1] : '0x'.$matches[1];
|
$r = strlen($matches[1]) == '1' ? '0x'.$matches[1].$matches[1] : '0x'.$matches[1];
|
||||||
$g = strlen($matches[2]) == '1' ? '0x'.$matches[2].$matches[2] : '0x'.$matches[2];
|
$g = strlen($matches[2]) == '1' ? '0x'.$matches[2].$matches[2] : '0x'.$matches[2];
|
||||||
$b = strlen($matches[3]) == '1' ? '0x'.$matches[3].$matches[3] : '0x'.$matches[3];
|
$b = strlen($matches[3]) == '1' ? '0x'.$matches[3].$matches[3] : '0x'.$matches[3];
|
||||||
|
|
||||||
// parse color string in format rgb(140, 140, 140)
|
} elseif (preg_match($rgbPattern, $value, $matches)) {
|
||||||
} elseif (preg_match('/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i', $value, $matches)) {
|
|
||||||
|
|
||||||
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
|
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
|
||||||
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
|
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
|
||||||
$b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
|
$b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
|
||||||
|
|
||||||
// parse color string in format rgba(255, 0, 0, 0.5)
|
} elseif (preg_match($rgbaPattern, $value, $matches)) {
|
||||||
} elseif (preg_match('/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,4})\)$/i', $value, $matches)) {
|
|
||||||
|
|
||||||
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
|
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
|
||||||
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
|
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
|
||||||
@@ -1523,7 +1530,9 @@ class Image
|
|||||||
for ($x=0; $x<$this->width; $x=$x+$step_x) {
|
for ($x=0; $x<$this->width; $x=$x+$step_x) {
|
||||||
for ($y=0; $y<$this->height; $y=$y+$step_y) {
|
for ($y=0; $y<$this->height; $y=$y+$step_y) {
|
||||||
$color = $this->pickColor($x, $y);
|
$color = $this->pickColor($x, $y);
|
||||||
if ($color['a'] < 1) return true;
|
if ($color['a'] < 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1583,9 +1592,7 @@ class Image
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Exception\InvalidImageTypeException(
|
throw new Exception("Wrong image type ({$this->type}) only use JPG, PNG or GIF images.");
|
||||||
"Wrong image type ({$this->type}) only use JPG, PNG or GIF images."
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,9 +31,11 @@ class ImageServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app['image'] = $this->app->share(function($app) {
|
$this->app['image'] = $this->app->share(
|
||||||
|
function ($app) {
|
||||||
return new Image;
|
return new Image;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user