The |embarque_src filter applied to an img tag passes its source as a Data URI Scheme encoded in base 64

  • New in : SPIP 2.1

The |embarque_src filter applied to a <img src="..." /> tag allows you to modify the src attribute to generate and retrieve the image as a base 64 encoded "Data URI Scheme" of the form: <img src="data:[<mediatype>][;base64],<data>" />.



<img src="squelettes/images/tdm.png" width='16' height='16' />


will return
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAFo9M/3AAAABGdBTUEAANb..."  width='16' height='16'>

...so the file will not be loaded from the source but displayed directly from the encoded string.

Size Limit
The purpose of this filter is to embed small images.
If the image passed in is too large (default 4kb), the filter will not be applied and will return the image path.

However, it is possible to force this setting

  1. [(#CHEMIN{img/newsletter_banner.png}|balise_img|embarque_src{9000})]

NB: this filter is provided by the plugin-dist compressor, through the PHP function filtre_embarque_src.
Caution : the result provided by this filter is not supported by all browsers or e-mail clients.

See also



Author jack Published : Updated : 20/09/22

Translations : English, français, Nederlands