1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 17:41:58 +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

@@ -94,7 +94,7 @@ class Image
public function __construct($source = null, $width = null, $height = null, $bgcolor = null)
{
// set image properties
if ( ! is_null($source)) {
if (! is_null($source)) {
if ($this->isImageResource($source)) {
@@ -166,7 +166,7 @@ class Image
*/
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(
'Please install package intervention/imagecache before
running this function.'
@@ -188,7 +188,7 @@ class Image
*/
private function initFromPath($path)
{
if ( ! file_exists($path)) {
if (! file_exists($path)) {
throw new Exception\ImageNotFoundException(
"Image file ({$path}) not found"
);
@@ -219,7 +219,7 @@ class Image
*/
private function initFromResource($resource)
{
if ( ! $this->isImageResource($resource)) {
if (! $this->isImageResource($resource)) {
throw new Exception\InvalidImageResourceException;
}
@@ -270,7 +270,7 @@ class Image
* @param integer $src_h
* @return Image
*/
private function modify($dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h)
private function modify($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
// create new image
$image = imagecreatetruecolor($dst_w, $dst_h);
@@ -280,7 +280,18 @@ class Image
imagesavealpha($image, true);
// 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
$this->resource = $image;
@@ -339,7 +350,7 @@ class Image
// If both width and hight have been passed along, the width and
// height parameters are maximum values.
if ( ! is_null($width) && ! is_null($height)) {
if (! is_null($width) && ! is_null($height)) {
// First, calculate the height.
$height = intval($width / $this->width * $this->height);
@@ -352,8 +363,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;
}
@@ -361,10 +372,10 @@ class Image
// If the image can't be upsized, check if the given width and/or
// height are too large.
if ( ! $upsize) {
if (! $upsize) {
// If the given width is larger then the image width,
// then don't resize it.
if ( ! is_null($width) && $width > $this->width) {
if (! is_null($width) && $width > $this->width) {
$width = $this->width;
// If ratio needs to be kept, height is recalculated.
@@ -375,7 +386,7 @@ class Image
// If the given height is larger then the image height,
// then don't resize it.
if ( ! is_null($height) && $height > $this->height) {
if (! is_null($height) && $height > $this->height) {
$height = $this->height;
// If ratio needs to be kept, width is recalculated.
@@ -569,7 +580,7 @@ class Image
$dst_y = ($height <= $this->height) ? 0 : intval(($height - $this->height) / 2);
// copy content from resource
imagecopy($image, $this->resource, $dst_x , $dst_y , $src_x , $src_y , $src_w , $src_h);
imagecopy($image, $this->resource, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
// set new content as recource
$this->resource = $image;
@@ -610,7 +621,7 @@ class Image
);
}
return $this->modify(0, 0, $pos_x , $pos_y, $width, $height, $width, $height);
return $this->modify(0, 0, $pos_x, $pos_y, $width, $height, $width, $height);
}
/**
@@ -632,7 +643,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;
@@ -647,7 +658,7 @@ class Image
$grab_width = $this->width;
$ratio = $grab_width / $width;
if($height * $ratio <= $this->height) {
if ($height * $ratio <= $this->height) {
$grab_height = round($height * $ratio);
$src_x = 0;
$src_y = round(($this->height - $grab_height) / 2);
@@ -1151,7 +1162,7 @@ class Image
*/
public function blur($amount = 1)
{
for ($i=0; $i < intval($amount); $i++) {
for ($i=0; $i < intval($amount); $i++) {
imagefilter($this->resource, IMG_FILTER_GAUSSIAN_BLUR);
}
@@ -1237,7 +1248,7 @@ class Image
case 'gif':
case 1:
imagegif($this->resource);
break;
break;
case 'png':
case 3:
@@ -1245,14 +1256,14 @@ class Image
imagealphablending($this->resource, false);
imagesavealpha($this->resource, true);
imagepng($this->resource, null, $quality);
break;
break;
default:
case 'jpg':
case 'jpeg':
case 2:
imagejpeg($this->resource, null, $quality);
break;
break;
}
$data = ob_get_contents();
@@ -1283,7 +1294,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':
@@ -1326,7 +1343,7 @@ class Image
// color is alread allocated
$allocatedColor = $value;
} elseif(is_array($value)) {
} elseif (is_array($value)) {
// parse color array like: array(155, 155, 155)
if (count($value) == 4) {
@@ -1342,30 +1359,30 @@ class Image
}
} elseif(is_string($value)) {
} 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;
$b = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
$a = $this->alpha2gd($matches[4]);
}
}
@@ -1415,7 +1432,7 @@ class Image
$data = exif_read_data($this->dirname .'/'. $this->basename, 'EXIF', false);
if ( ! is_null($key)) {
if (! is_null($key)) {
return array_key_exists($key, $data) ? $data[$key] : null;
}
@@ -1489,7 +1506,6 @@ class Image
// There was a logical error in the program that wasn't considered.
// Namely, how should the program handle a valid resource handle
// that wasn't a valid image resource handle.
//
// Previously this method simply returned false if $input wasn't
// a valid image resource handle. But in the constructor, the next
// 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 ($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;
}
}
}
@@ -1569,24 +1587,24 @@ class Image
switch ($this->type) {
case IMG_PNG:
case 3:
$this->resource = imagecreatefrompng($path);
break;
$this->resource = imagecreatefrompng($path);
break;
case IMG_JPG:
case 2:
$this->resource = imagecreatefromjpeg($path);
break;
$this->resource = imagecreatefromjpeg($path);
break;
case IMG_GIF:
case 1:
$this->resource = imagecreatefromgif($path);
break;
$this->resource = imagecreatefromgif($path);
break;
default:
throw new Exception\InvalidImageTypeException(
"Wrong image type ({$this->type}) only use JPG, PNG or GIF images."
);
break;
throw new Exception\InvalidImageTypeException(
"Wrong image type ({$this->type}) only use JPG, PNG or GIF images."
);
break;
}
}

View File

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