VCardParser: rewrite contact photo code as a function

Rewrite the code as a function, so we can make an early return if a check fails.

Bugfix: the old code did not properly recognize differences between uppercase
and lowercase encoding strings: 'b' was different from 'B', which broke some
clients (as posted to the Zarafa forum).

Also build in more sanity checks, such as checking whether the GD extension is
loaded before trying to use it.