1
0
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:
Eric Jones
2013-09-20 15:15:46 -04:00
parent 62ec665340
commit 5c459429a0
2 changed files with 62 additions and 46 deletions

View File

@@ -347,8 +347,8 @@ class Image
$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;
$height = is_null($height) ? intval($width / $this->width * $this->height) : $height;
}
@@ -625,7 +625,7 @@ class Image
$width = is_numeric($width) ? intval($width) : 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
$width = is_null($width) ? $height : $width;
$height = is_null($height) ? $width : $height;
@@ -1271,7 +1271,13 @@ class Image
case 'rgba':
$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;
case 'hex':
@@ -1333,21 +1339,27 @@ class Image
} elseif (is_string($value)) {
// 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];
$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];
// parse color string in format rgb(140, 140, 140)
} elseif (preg_match('/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i', $value, $matches)) {
} elseif (preg_match($rgbPattern, $value, $matches)) {
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
$g = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 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('/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,4})\)$/i', $value, $matches)) {
} elseif (preg_match($rgbaPattern, $value, $matches)) {
$r = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 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 ($y=0; $y<$this->height; $y=$y+$step_y) {
$color = $this->pickColor($x, $y);
if ($color['a'] < 1) return true;
if ($color['a'] < 1) {
return true;
}
}
}

View File

@@ -31,9 +31,11 @@ class ImageServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app['image'] = $this->app->share(function($app) {
$this->app['image'] = $this->app->share(
function ($app) {
return new Image;
});
}
);
}
/**