note 88436 deleted from function.imagerotate by cmb
| From: | cmb@php.net | Date: | Mon, 22 Aug 2016 10:24:35 +0000 |
| Subject: | note 88436 deleted from function.imagerotate by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206362@lists.php.net to get a copy of this message | ||
Note Submitter: Kae Cyphet
----
To solve that annoying problem of having to install a pre-compiled version of GD just to get
imagerotate working.
here is an open source solution.
uses the standard stuff included in php when you uncomment 'extension=php_gd2.dll' in the
php.ini file and there ya go!
Useage:
<?php
$im = imagecreatefromjpeg('test.jpg');
header('Content-type: image/jpg');
imagejpeg(rotate_right90($im));
imagedestroy($im);
?>
'=================================
<?php
function rotate_right90($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($hei,$wid);
for($i = 0;$i < $wid; $i++)
{
for($j = 0;$j < $hei; $j++)
{
$ref = imagecolorat($im,$i,$j);
imagesetpixel($im2,$hei - $j,$i,$ref);
}
}
return $im2;
}
function rotate_left90($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($hei,$wid);
for($i = 0;$i < $wid; $i++)
{
for($j = 0;$j < $hei; $j++)
{
$ref = imagecolorat($im,$i,$j);
imagesetpixel($im2,$j, $wid - $i,$ref);
}
}
return $im2;
}
function mirror($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($wid,$hei);
for($i = 0;$i < $wid; $i++)
{
for($j = 0;$j < $hei; $j++)
{
$ref = imagecolorat($im,$i,$j);
imagesetpixel($im2,$wid - $i,$j,$ref);
}
}
return $im2;
}
function flip($im)
{
$wid = imagesx($im);
$hei = imagesy($im);
$im2 = imagecreatetruecolor($wid,$hei);
for($i = 0;$i < $wid; $i++)
{
for($j = 0;$j < $hei; $j++)
{
$ref = imagecolorat($im,$i,$j);
imagesetpixel($im2,$i,$hei - $j,$ref);
}
}
return $im2;
}
?>