Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

displaying vCard photos

by mellin (Scribe)
on Apr 14, 2006 at 20:09 UTC ( #543433=perlquestion: print w/replies, xml ) Need Help??

mellin has asked for the wisdom of the Perl Monks concerning the following question:

I'm in the middle of writing a Perl program that writes and displays vCards. One thing that confuses me is the PHOTO field. Could it be possible to export them onto standard JPEG files? I'd like to create an application that produces HTML files on-the-fly and displays those photo fields, too.

The line below is what i'm talking about. I understand it says "this data is in Jpeg image format and encoded as Base64". Now how should this data be displayd to a web browser, or alternatively, saved to a file?

PHOTO;JPEG;BASE64:

Replies are listed 'Best First'.
Re: displaying vCard photos
by Happy-the-monk (Canon) on Apr 14, 2006 at 20:20 UTC

    Now how should this data be displayd to a web browser, or alternatively, saved to a file?

    Hmm, use MIME::Base64 to decode it, save it to a file with the proper .jpg or .jpeg-extension, then use HTML's <img>-Tag to link it to your web page?

    Cheers, Sören

Re: displaying vCard photos
by rjray (Chaplain) on Apr 15, 2006 at 00:21 UTC

    That is tricky, since the nature of HTML assumes that the source for an IMG tag is a wholly separate URI, and not inline. I think they might be making allowances for this in XHTML 2.0, but I don't know for sure (and it doesn't exactly help you either way).

    As another commenter noted, you could save the content to a file and refer to the file in your SRC attribute. Of course, that will lead to another HTTP request, so you have to either put it in a place that your server already uses for content, have some sort of aliasing set up, or have your script handle both types of request-- the vCard proper and the image attachments. That is what I would do-- have the same script (I assume this is CGI?) that displays the vCard-as-HTML also have a calling-form to fetch the image content. Then return that content with proper Last-Modified, Content-Type, etc. headers and such based on the timestamp of the vCard itself.

    --rjray

      That is tricky, since the nature of HTML assumes that the source for an IMG tag is a wholly separate URI, and not inline.

      A data uri could be used to display an inline image created on the fly. It would look something like this:

      <img src="data:image/jpeg;base64,11111111111111111111111111" />
      where the 1's represent the base64 encoded bytes. Mozilla supports it but does the eighty ton gorilla? It looks like it might not.

      --
      જલધર

        I didn't mention it because I wasn't sure how well-supported it was. I do that in GreaseMonkey scripts, to embed icons within the script, but then I know in those cases that I'm in a Firefox/Mozilla environment.

        I stand by my opinion that having the script do double-duty (return HTML or image data based on parameters in the query) is probably going to yield the cleanest, most-maintainable result.

        --rjray

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://543433]
Approved by Thelonius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-06-28 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (90 votes). Check out past polls.

    Notices?