If you can use ImageMagick on your server you might want to give this a try:
convert koala.gif -background Blue -wave 10x64 wave.jpg
UPDATE:
If you aren't using some library you will obviously have to write your own implementation.
Here are some suggestions where you can find useful informations on that:
If you are more of a hands on guy have a look at this freely available Java implementation of a SwimFilter or WarpFilter that can be downloaded here
Then there's an explanation of the 2-spline mash warping algorithm that might do what you want here.
Here's a good overview over algorithms that might suit your needs(Microsoft doc file).
You should be aware though that this isn't something that's easily implemented. But if you are interested in the topic and really really have to live withouth ImageMagick than that's your only chance(as far as I know).
And then there's also GD's bad performance..
Good luck! :-)