dataurl

Data URLs and QueryPath: How to embed images into XML or HTML

QueryPath 2.1 is adding support for writing files directly into URLs using Data URLs. What this means is that you can encode and embed images or other documents straight into your HTML or XML.

Here's a simple example from the QueryPath 2.1 unit tests:

<?php
$xml = '<?xml version="1.0"?><root><item/></root>';
qp($xml, 'item')->dataURL('secret', 'Hi!', 'text/plain');
?>

The above will generate an XML fragment that looks like this:

<?xml version="1.0"?>
<root>
  <item secret="data:text/plain;base64,SGkh"/>
</root>

The important part there is the attribute secret="data:text/plain;base64,SGkh. This attribute includes an embedded text document with the contents Hi!. What we've done is encode the data and injected it as a document inside of the XML.

Sure, that's novel... but what would we want to use that for? How about adding images directly into a document?

Syndicate content