Upgrade—Base64 Encoding

imgix logo
Team imgix
March 1, 2016
3 minute read

Some of imgix's most powerful features, like watermarks and multiline text, require passing in a URL or a text string as the value of a parameter. For these parameters, we've recommended that both URLs and strings be URI-encoded.

Today we're announcing Base64 encoding support for these parameters, to ensure that they resolve correctly even when nested several levels deep. This makes doing complex composting with imgix more reliable and easier to implement.

For example, to add a watermark, you would grab the URL of the graphic that you're using for the mark, encode it, and then make the encoded URL the value of mark.


Base Image


mark=* (see parameters below)

Watermark Image



In this example, the entire watermark URL must be pre-encoded before being passed to the mark parameter, so the final URL for the watermarked image looks like this:


New Base64 Support

That all works fine with standard URI-encoding, but adding text into the mix can be a bit tricky in these nested multi-layer compositions. Unless generated carefully, the need to encode the text and then encode the URL that it's part of could end up displaying the codes rather than the text.

To remove this issue, we've added Base64 encoding support to all parameters. To use it, add 64 to the parameter name, then Base64-encode the URL or text string and add it as the parameter value. This will be particularly useful for the following parameters, which often include user-generated text or comma-separated values.

So, for example, if we wanted to add a line of text at the bottom of the image using the Typesetting Endpoint, we need to create the text URL, encode it, and then add it as the value of blend (because mark has already been used). However, the emoji, spaces, and comma-separated value of txtalign would have been potentially problematic with standard URI encoding when passed to another parameter.

Text endpoint example


However, with Base64 encoding, all such URLs are completely safe and nestable. The link above will become the following when Base64-encoded instead, and can then be passed safely to the blend64 parameter:


The final URL, with the text added and Base64 on all relevant parameters, would look like this:


which results in the final image:

Generating Base64-encoded parameters is easy in many languages, and the imgix client libraries are being updated to automatically encode strings passed to Base64 variant parameters. Check whichever library you’re using for specific details of its implementation. We use the URL-safe alphabet for Base64 encoding.

See the Image URL API documentation for more information about our Base64 encoding support.