Your photos and contacts can generally be transferred to the new library without any problems via the initial sync to/from the new library. You will need to configure your target photo sync location (probably either iPhoto or a directory).
However, with music (and probably movies), transferring depends on the original source. If you purchased them through iTunes, authorize the computer/new library and transfer your purchases. However, if not all of the music was obtained via iTunes, you will need to transfer the music from the iPhone to the computer, or you'll lose them during the initial sync. This transfer can be accomplished by a number of different software programs. You can then manually add the music to the new library.
Finally, this wiki article contains a number of links that discuss methods to transfer data from iPhone to both PCs and Macs. Note: The software used in the wiki seem to be freeware, but I can't vouch for them, as I've never used those programs before.