mirror of
https://github.com/Intervention/image.git
synced 2025-08-12 17:03:59 +02:00
Fix the code to be PSR-2 compliant
This commit is contained in:
@@ -347,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;
|
||||||
}
|
}
|
||||||
@@ -625,7 +625,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;
|
||||||
@@ -1271,7 +1271,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':
|
||||||
@@ -1333,21 +1339,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;
|
||||||
@@ -1478,7 +1490,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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