Get Asset version related to image change -color/size



Hi All, 


We are having a use case to get an asset version related to change in the asset birany (image itself such as image color, size change, not in metadata), not related to metadata change.

AEM creates an asset version for metadata and binary changes and stores into /jcr:system/jcr:versionStorage.

Can you guys please suggest an approach to get asset version related to binary change only, not metadata change?


Thanks in advance. 


Asset image versioning

Accepted Solutions (1)

Accepted Solutions (1)





One way you could do this is by looking at the dam:size property of the asset, which is the size of the image in bytes. It does not change if you add or edit metadata (eg: Title), but it will change if authors edit the image. You won't be able to tell what changed specifically (could be flip, rotate or complete image change for example), but you'll be able to tell which revisions include image modifications.

Here is a quick-and-dirty servlet that does this comparison:



And here is the code:

@component(service = Servlet.class,
        property = {
                "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                "sling.servlet.paths=" + "/bin/metadata"
@ServiceDescription("Simple Demo Servlet")
public class SimpleServlet extends SlingSafeMethodsServlet {

    private static final long serialVersionUID = 1L;

    private SlingHttpServletResponse response;

    protected void doGet(final SlingHttpServletRequest req,
                         final SlingHttpServletResponse resp) throws ServletException, IOException {
        response = resp;

        final Asset asset = req.getResourceResolver().getResource("/content/dam/demo/image.jpg").adaptTo(Asset.class);

        final long currentSize = (long) asset.getMetadata().get(;

        final Collection<Revision> revisions;
        try {
            // Get all revisions
            final AssetManager assetManager = asset.adaptTo(AssetManager.class);
            revisions = assetManager.getRevisions(asset.getPath(), null);
            output("Revisions: " + revisions.size());

            // Sort by date
            final ArrayList<Revision> list = new ArrayList<>(revisions);

            long latestSize = currentSize;
            for (final Revision revision : revisions) {
                final ValueMap metadata = revision.getMetadataProperties();
                final GregorianCalendar calendar = (GregorianCalendar) metadata.get(;
                final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

                // Determine if the image was changed
                final long revisionSize = (long) revision.getMetadataProperties().get(;
                final boolean imageChanged = revisionSize != latestSize;

                if (imageChanged) {
                    latestSize = revisionSize;

                // Output result
                output(formatter.format(calendar.getTime()) + " | Image changed: " + imageChanged);
        } catch (final Exception e) {
            log.error("Unexpected error", e);

    private int sortRevisionsByDateDesc(final Revision a, final Revision b) {
        final GregorianCalendar calendarA = (GregorianCalendar) a.getMetadataProperties().get("dc:modified");
        final GregorianCalendar calendarB = (GregorianCalendar) b.getMetadataProperties().get("dc:modified");
        return calendarA.compareTo(calendarB) * -1;

    private void output(final String string) throws IOException {


Answers (0)