1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 02:12:37 +02:00

Fixed lost changes due to incorrectly merging branches.

This commit is contained in:
Eric Jones
2013-09-24 09:14:14 -04:00
parent c60495c6f1
commit 6f41121403
2 changed files with 69 additions and 49 deletions

View File

@@ -280,7 +280,18 @@ class Image
imagesavealpha($image, true); imagesavealpha($image, true);
// copy content from resource // copy content from resource
imagecopyresampled($image, $this->resource, $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h); imagecopyresampled(
$image,
$this->resource,
$dst_x,
$dst_y,
$src_x,
$src_y,
$dst_w,
$dst_h,
$src_w,
$src_h
);
// set new content as recource // set new content as recource
$this->resource = $image; $this->resource = $image;
@@ -352,8 +363,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 +643,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 +1294,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,27 +1362,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];
} elseif (preg_match($rgbPattern, $value, $matches)) {
// 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)) {
$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;
} elseif (preg_match($rgbaPattern, $value, $matches)) {
// 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)) {
$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;
$a = $this->alpha2gd($matches[4]); $a = $this->alpha2gd($matches[4]);
} }
} }
@@ -1489,7 +1506,6 @@ class Image
// There was a logical error in the program that wasn't considered. // There was a logical error in the program that wasn't considered.
// Namely, how should the program handle a valid resource handle // Namely, how should the program handle a valid resource handle
// that wasn't a valid image resource handle. // that wasn't a valid image resource handle.
//
// Previously this method simply returned false if $input wasn't // Previously this method simply returned false if $input wasn't
// a valid image resource handle. But in the constructor, the next // a valid image resource handle. But in the constructor, the next
// conditional passed the file handle to the Image::isBinary method. // conditional passed the file handle to the Image::isBinary method.
@@ -1523,7 +1539,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;
}
} }
} }

View File

@@ -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;
}); }
);
} }
/** /**