mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
mujma: BUGFIX: Added rotatePixelByPixel method to add rotate functionality on machines where imagerotate function it's not available Ubuntu. (merged from branches/gsoc)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41718 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
85bd9b0460
commit
5a74d0e63d
@ -135,13 +135,59 @@ class GD extends Object {
|
||||
function rotate($angle) {
|
||||
if(!$this->gd) return;
|
||||
|
||||
$newGD = imagerotate($this->gd, $angle,0);
|
||||
|
||||
if(function_exists("imagerotate")) {
|
||||
$newGD = imagerotate($this->gd, $angle,0);
|
||||
} else {
|
||||
//imagerotate is not included in PHP included in Ubuntu
|
||||
$newGD = $this->rotatePixelByPixel($angle);
|
||||
}
|
||||
$output = new GD();
|
||||
$output->setGD($newGD);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates image by given angle. It's slow because makes it pixel by pixel rather than
|
||||
* using built-in function. Used when imagerotate function is not available(i.e. Ubuntu)
|
||||
*
|
||||
* @param angle
|
||||
|
||||
* @return GD
|
||||
*/
|
||||
|
||||
function rotatePixelByPixel($angle) {
|
||||
$sourceWidth = imagesx($this->gd);
|
||||
$sourceHeight = imagesy($this->gd);
|
||||
if ($angle == 180) {
|
||||
$destWidth = $sourceWidth;
|
||||
$destHeight = $sourceHeight;
|
||||
} else {
|
||||
$destWidth = $sourceHeight;
|
||||
$destHeight = $sourceWidth;
|
||||
}
|
||||
$rotate=imagecreatetruecolor($destWidth,$destHeight);
|
||||
imagealphablending($rotate, false);
|
||||
for ($x = 0; $x < ($sourceWidth); $x++) {
|
||||
for ($y = 0; $y < ($sourceHeight); $y++) {
|
||||
$color = imagecolorat($this->gd, $x, $y);
|
||||
switch ($angle) {
|
||||
case 90:
|
||||
imagesetpixel($rotate, $y, $destHeight - $x - 1, $color);
|
||||
break;
|
||||
case 180:
|
||||
imagesetpixel($rotate, $destWidth - $x - 1, $destHeight - $y - 1, $color);
|
||||
break;
|
||||
case 270:
|
||||
imagesetpixel($rotate, $destWidth - $y - 1, $x, $color);
|
||||
break;
|
||||
default: $rotate = $this->gd;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $rotate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Crop's part of image.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user