note 42803 added to function.imagecopy
| From: | lecoguic at yahoo dot fr | Date: | Sun, 30 May 2004 08:25:39 +0000 |
| Subject: | note 42803 added to function.imagecopy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70298@lists.php.net to get a copy of this message | ||
Here is a function to flip an image using imagecopy, just replace SRC_IMAGE and DEST_IMAGE with your
own filename
(works only for jpg source image)
<?
define("MIRROR_HORIZONTAL", 1);
define("MIRROR_VERTICAL", 2);
define("MIRROR_BOTH", 3);
function Mirror($src, $dest, $type)
{
$imgsrc = imagecreatefromjpeg($src);
$width = imagesx($imgsrc);
$height = imagesy($imgsrc);
$imgdest = imagecreatetruecolor($width, $height);
for ($x=0 ; $x<$width ; $x++)
{
for ($y=0 ; $y<$height ; $y++)
{
if ($type == MIRROR_HORIZONTAL) imagecopy($imgdest, $imgsrc, $width-$x-1, $y, $x, $y, 1, 1);
if ($type == MIRROR_VERTICAL) imagecopy($imgdest, $imgsrc, $x, $height-$y-1, $x, $y, 1, 1);
if ($type == MIRROR_BOTH) imagecopy($imgdest, $imgsrc, $width-$x-1, $height-$y-1, $x, $y, 1, 1);
}
}
imagejpeg($imgdest, $dest);
imagedestroy($imgsrc);
imagedestroy($imgdest);
}
Mirror(SRC_IMAGE, DEST_IMAGE, MIRROR_HORIZONTAL);
print "<img src='SRC_IMAGE'>";
print "<br><br>";
print "<img src='DEST_IMAGE'>";
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopy.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42803
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42803&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42803&report=yes
Search -- http://master.php.net/manage/user-notes.php