AEM integration with webp

A question from my colleagues in regards to AEM’s support for webp started a research path. Since, I took more than 1 year pause from AEM, I started looking around for the possibility of serving also webp images, for all the images already in DAM.

As a first step I started ask the community on stackoverflow and Adobe Forum. The answer received was to use a webp java library that provides support for reading and writing webp images .

Note: You will notice I have usedcom.github.nintha library. At the end of the article I will explain the reasoning for it and how I actually ditched it to work.

The steps for resolving this were:

  1. To add the 3rd party jar to AEM
  2. Create a simple servlet that receives as queryparam the image path as and returns the webp image.

Adding the 3rd party jar

In AEM one can install via in Apache Felix only bundled jar, for the simple jars, one can embed them using the maven-bundle-plugin in tree steps:

  1. Add the library jar to your application pom.xml (the main one)

2. Modify the pom.xml from the core app to add the dependency and embed the jar. The core/pom.xml will have something like:


Things to mention: the Embed-Dependency tag needs to be populated with the artifactId. The <Embed-Transitive> tag specifies to embed also the dependencies of the embedded jar. (eg. the webp-imageio-core has as dependency org.scijava – native-lib-loader, which will be embedded as well)

In order to test that your 3rd party was successfully embedded, one can take a look at the bundle information:

Verify that:
– Bundle Classpath includes the 3rd party jar
– The manifest header contains the embedded dependencies, artifacts and transitive set as expected

Create the Servlet to transform to webp

For the purposes of this POC, it will be only a basic Servlet, it can be enhanced, of course to work with image renditions, or to work receive the path as a suffix – which would be the right way as we want the images to be cached.

package andra.core.servlets;

import com.luciad.imageio.webp.WebPWriteParam;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.osgi.framework.Constants;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.servlet.ServletException;
import java.awt.image.BufferedImage;

@SlingServlet(paths = "/bin/webpTransformer",
methods = HttpConstants.METHOD_GET
@Property(name = Constants.SERVICE_DESCRIPTION, value = "WebP Transformer Servlet")
public class WepServlet extends SlingSafeMethodsServlet {

public static final String IMAGE_WEBP = "image/webp";

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

BufferedImage image = getImage(request);

// Obtain a WebP ImageWriter instance
ImageWriter writer = ImageIO.getImageWritersByMIMEType(IMAGE_WEBP).next();

// Configure encoding parameters
WebPWriteParam writeParam = new WebPWriteParam(writer.getLocale());
ImageOutputStream outputStream = new MemoryCacheImageOutputStream(

// Configure the output on the ImageWriter

// Encode
writer.write(null, new IIOImage(image, null, null), writeParam);


private BufferedImage getImage(SlingHttpServletRequest request) throws IOException {
ResourceResolver resourceResolver = request.getResourceResolver();
String path = request.getParameter("path");
Resource res = resourceResolver.getResource(path);
Asset asset = res.adaptTo(Asset.class);


Why and how nintha ?

A question I would ask is why use nintha over luciad, as in the end nintha is just a luciad wrapper. Of course, I always try to use the standard lib, where possible, however when embedding luciad compiled on my machine I would get the following error:

Could not initialize class com.luciad.imageio.webp.WebPEncoderOptions
Cannot serve request to /bin/webpTransformer in andra.core.servlets.WepServlet

java.lang.NoClassDefFoundError: Could not initialize class com.luciad.imageio.webp.WebPEncoderOptions
at com.luciad.imageio.webp.WebPWriteParam.(
at com.luciad.imageio.webp.WebPWriter.getDefaultWriteParam(

After a couple of days, I decided to give nintha a go. However, it did not go as smooth as I wanted, as know I would receive:

org.scijava.nativelib.NativeLibraryUtil Problem with library

Meaning, that the native library included in nintha was not compatible with the OS the app was running. So, I had to add compile the native app on my local machine, add it manually to the nintha library and recomile. This is not a solution I like as it would be a downside when migration to another server – the library needs to encapsulate the native app for the specific environment.

Leave a Reply

Your email address will not be published. Required fields are marked *