Last active
July 8, 2019 05:33
-
-
Save mgng/dd58b34e41effbf490994a253277883c to your computer and use it in GitHub Desktop.
how to create a wave image by PHP(GD)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param resource $img | |
* @param int $width | |
* @param int $height | |
* @param int $period | |
* @param int $amplitude | |
* @return resource | |
*/ | |
function imageWave($img, $width, $height, $period = 10, $amplitude = 5) { | |
$p = $period * rand(1, 3); | |
$k = mt_rand(0, 100); | |
for ($i = 0; $i<$width; $i++) { | |
imagecopy($img, $img, $i-1, sin($k+$i/$p) * $amplitude, $i, 0, 1, $height); | |
} | |
$k = mt_rand(0,100); | |
for ($i = 0; $i<$height; $i++) { | |
imagecopy($img, $img, sin($k+$i/$p) * $amplitude, $i-1, 0, $i, $width, 1); | |
} | |
return $img; | |
} | |
$img = imagecreatefromjpeg("test.jpg"); | |
$img = imageWave($img, imagesx($img), imagesy($img)); | |
imagejpeg($img, "out.jpg"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment