PHP 8.5.0 Alpha 1 available for testing

Voting

: max(seven, one)?
(Example: nine)

The Note You're Voting On

john at mccarthy dot net
18 years ago
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));

<< Back to user notes page

To Top