note 72393 added to function.imagecopy
| From: | john at mccarthy dot net | Date: | Wed, 17 Jan 2007 13:37:22 +0000 |
| Subject: | note 72393 added to function.imagecopy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121832@lists.php.net to get a copy of this message | ||
Here is an upgrade of that cool wave function: Double the size of the image, wave it, then resample
it down again. This makes even nicer, anti aliased waves.
// So easy and nice!
function wave_region($img, $x, $y, $width, $height,$amplitude = 4.5,$period = 30)
{
// Make a copy of the image twice the size
$mult = 2;
$img2 = imagecreatetruecolor($width * $mult, $height * $mult);
imagecopyresampled ($img2,$img,0,0,$x,$y,$width * $mult,$height * $mult,$width, $height);
// Wave it
for ($i = 0;$i < ($width * $mult);$i += 2)
{
imagecopy($img2,$img2,
$x + $i - 2,$y + sin($i / $period) * $amplitude, // dest
$x + $i,$y, // src
2,($height * $mult));
}
// Resample it down again
imagecopyresampled ($img,$img2,$x,$y,0,0,$width, $height,$width * $mult,$height * $mult);
imagedestroy($img2);
}
To use it in a full image:
wave_region ($oImage,0,0,imagesx($oImage),imagesy($oImage));
----
Server IP: 69.147.83.197
Probable Submitter: 75.80.185.96
----
Manual Page -- http://www.php.net/manual/en/function.imagecopy.php
Edit -- https://master.php.net/note/edit/72393
Del: integrated -- https://master.php.net/note/delete/72393/integrated
Del: useless -- https://master.php.net/note/delete/72393/useless
Del: bad code -- https://master.php.net/note/delete/72393/bad+code
Del: spam -- https://master.php.net/note/delete/72393/spam
Del: non-english -- https://master.php.net/note/delete/72393/non-english
Del: in docs -- https://master.php.net/note/delete/72393/in+docs
Del: other reasons-- https://master.php.net/note/delete/72393
Reject -- https://master.php.net/note/reject/72393
Search -- https://master.php.net/manage/user-notes.php