This isn't a code writing service. You have to show some effort or you will not get good responses.
You should start by reading the docs for GD and Image::Magick. Study and try out all of the demos and test cases (they both include those). Search this site for posts about those modules and learn more about them. Then when you've done all of that, you should be in a position to write the script you want. If it doesn't work, you can make a new post that not only tells what is and isn't working but also shows the code so that we can help you with it.