ImageBundleBuilder builder = getBuilder(method);
URL resource = resources[0];
String name = method.getName();
ImageRect rect;
try {
rect = builder.assimilate(logger, name, resource);
if (context.supportsDataUrls()
|| getRepeatStyle(method) == RepeatStyle.Both) {
// Just use the calculated meta-data
builder.removeMapping(name);
rect.setPosition(0, 0);
throw new UnsuitableForStripException(rect);
}
buildersByImageRect.put(rect, builder);
} catch (UnsuitableForStripException e) {
// Add the image to the output as a separate resource
rect = e.getImageRect();
String urlExpression;
if (rect.isAnimated()) {
// Can't re-encode animated images, so we emit it as-is
urlExpression = context.deploy(resource, false);
} else {
// Re-encode the image as a PNG to strip random header data
byte[] imageBytes = ImageBundleBuilder.toPng(logger, rect);
urlExpression = context.deploy(rect.getName() + ".png", "image/png",
imageBytes, false);
}
urlsByExternalImageRect.put(rect, new String[] {urlExpression, null});
}