We can further manipulate images through the use of pdf_rotate() and pdf_skew() - two functions you should be able to guess quite easily.
As per usual, both pdf_rotate() and pdf_skew() take a PDF document reference as their first parameter. pdf_rotate() then takes one extra parameter - how much to rotate the co-ordinate system by, in degrees - whereas pdf_skew takes two extra parameters - how much to skew the co-ordinate system by in the X direction and how much in the Y direction.
Try adding these two lines just after the call to pdf_begin_page() inside the loop:
Re-save the file and generate the PDF file again. You may need to comment one of the lines out at a time to clearly see what effect each call has on your document, however you should also notice that these two functions allow you to rotate and skew your text as well as your pictures.