Skip to content

Commit

Permalink
added checks for imageantialias function existence
Browse files Browse the repository at this point in the history
  • Loading branch information
avalanche123 committed Feb 27, 2011
1 parent 7139ab9 commit f80c68a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
27 changes: 21 additions & 6 deletions lib/Imagine/Gd/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ final public function copy()
}

if (false === imagealphablending($copy, false) ||
false === imagesavealpha($copy, true) ||
false === imageantialias($copy, true)) {
false === imagesavealpha($copy, true)) {
throw new RuntimeException('Image copy operation failed');
}

if (function_exists('imageantialias')) {
imageantialias($copy, true);
}

if (false === imagecopymerge($copy, $this->resource, 0, 0, 0,
0, $size->getWidth(), $size->getHeight(), 100)) {
throw new RuntimeException('Image copy operation failed');
Expand Down Expand Up @@ -101,7 +104,10 @@ final public function crop(PointInterface $start, BoxInterface $size)

imagealphablending($dest, false);
imagesavealpha($dest, true);
imageantialias($dest, true);

if (function_exists('imageantialias')) {
imageantialias($dest, true);
}

if (false === imagecopymerge($dest, $this->resource, 0, 0,
$start->getX(), $start->getY(), $width, $height, 100)) {
Expand Down Expand Up @@ -165,7 +171,10 @@ final public function resize(BoxInterface $size)

imagealphablending($dest, false);
imagesavealpha($dest, true);
imageantialias($dest, true);

if (function_exists('imageantialias')) {
imageantialias($dest, true);
}

if (false === imagecopyresampled($dest, $this->resource, 0, 0, 0, 0,
$width, $height, imagesx($this->resource), imagesy($this->resource)
Expand Down Expand Up @@ -258,7 +267,10 @@ final public function flipHorizontally()

imagealphablending($dest, false);
imagesavealpha($dest, true);
imageantialias($dest, true);

if (function_exists('imageantialias')) {
imageantialias($dest, true);
}

for ($i = 0; $i < $width; $i++) {
if (false === imagecopymerge($dest, $this->resource, $i, 0,
Expand Down Expand Up @@ -286,7 +298,10 @@ final public function flipVertically()

imagealphablending($dest, false);
imagesavealpha($dest, true);
imageantialias($dest, true);

if (function_exists('imageantialias')) {
imageantialias($dest, true);
}

for ($i = 0; $i < $height; $i++) {
if (false === imagecopymerge($dest, $this->resource, 0, $i,
Expand Down
21 changes: 13 additions & 8 deletions lib/Imagine/Gd/Imagine.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ public function create(BoxInterface $size, Color $color = null)
$color = $color ? $color : new Color('fff');

if (false === imagealphablending($resource, false) ||
false === imagesavealpha($resource, true) ||
false === imageantialias($resource, true)) {
false === imagesavealpha($resource, true)) {
throw new RuntimeException(
'Could not set alphablending, savealpha and antialias values'
);
}

if (function_exists('imageantialias')) {
imageantialias($resource, true);
}

$color = imagecolorallocatealpha(
$resource, $color->getRed(), $color->getGreen(), $color->getBlue(),
round(127 * $color->getAlpha() / 100)
Expand Down Expand Up @@ -131,14 +134,15 @@ public function open($path)
}

if (false === imagealphablending($resource, false) ||
false === imagesavealpha($resource, true) ||
false === imageantialias($resource, true)) {
false === imagesavealpha($resource, true)) {
throw new RuntimeException(
'Could not set alphablending, savealpha and antialias values'
);
}

imageantialias($resource, true);
if (function_exists('imageantialias')) {
imageantialias($resource, true);
}

return new Image($resource);
}
Expand All @@ -156,14 +160,15 @@ public function load($string)
}

if (false === imagealphablending($resource, false) ||
false === imagesavealpha($resource, true) ||
false === imageantialias($resource, true)) {
false === imagesavealpha($resource, true)) {
throw new RuntimeException(
'Could not set alphablending, savealpha and antialias values'
);
}

imageantialias($resource, true);
if (function_exists('imageantialias')) {
imageantialias($resource, true);
}

return new Image($resource);
}
Expand Down

0 comments on commit f80c68a

Please sign in to comment.