State of Ameto – The Java Client

Michael Seifert, 2018-04-12

As previously mentioned on the Ameto newsletter we are working on a programming library in Java for interacting with Ameto. The library allows you to manage processing pipelines, assets, and jobs. The following code sample shows the necessary code to generate thumbnail images. The source code is based on one of our test cases:

Ameto ameto = new Ameto(apiUrl, apiToken);
Pipeline pipeline = ameto.add("thumbnail", "image/jpeg", Arrays.asList(
    ameto.getOperator("auto_orient"),
    ameto.getOperator("resize", 640, 480),
    ameto.getOperator("strip_metadata"),
    ameto.getOperator("shrink")
));
Asset asset = ameto.add(Paths.get("src/test/resources/flower.jpg"));

ProcessedAsset processedAsset = pipeline.push(asset);

byte[] thumbnail = processedAsset.getEssence();

At the beginning, we initialize the library by creating an Ameto object. This allows us to create pipelines and upload assets. The processing pipeline created in this example normalizes the image's orientation based on Exif metadata, resizes it to 640x480 px, removes all metadata, and optimizes the image for size.11 see our previous blog post After both the pipeline and an asset are present, we create a new job by pushing the asset into the pipeline. The result contains the thumbnail represented as a byte array.

The calls to the Ameto API are synchronous. However, it is possible to interact with Ameto in an asynchronous fashion by using Java's built-in CompletableFuture:

Future<byte[]> thumbnail = CompletableFuture
  .supplyAsync(() -> ameto.add(Paths.get("src/test/resources/flower.jpg")))
  .thenApply(pipeline::push)
  .thenApply(ProcessedAsset::getEssence);

The Ameto client library for Java will soon be available for testing. Feel free to reach out to us via Twitter, email, or otherwise, if you have any comments or suggestions.