Skip to content

imageboss/java-imageboss

Repository files navigation

imageboss-java

Java URL builder for ImageBoss, with Java 17+ and Kotlin support.

Installation

Add the dependency

Gradle (Kotlin DSL)

dependencies {
    implementation("me.imageboss:imageboss-java:1.0.0")
}

Maven

<dependency>
  <groupId>me.imageboss</groupId>
  <artifactId>imageboss-java</artifactId>
  <version>1.0.0</version>
</dependency>

Basic usage (Java)

import me.imageboss.ImageBossClient;
import me.imageboss.Operation;
import me.imageboss.Option;

ImageBossClient client = ImageBossClient.newBuilder("mywebsite-images").build();

String url = client.createUrl(
    "examples/02.jpg",
    Operation.cover(300, 300),
    Option.formatAuto()
);
// https://img.imageboss.me/mywebsite-images/cover/300x300/format:auto/examples/02.jpg

Signed URLs

ImageBossClient client = ImageBossClient.newBuilder("mysecureimages")
    .secret("<YOUR_SECRET>")
    .build();

String url = client.createUrl("width/500/01.jpg", Operation.cdn());
// https://img.imageboss.me/mysecureimages/cdn/width/500/01.jpg?bossToken=...

Expiring URLs:

long expires = /* unix timestamp (seconds) */;
String url = client.createSignedUrl(
    "width/500/01.jpg",
    Operation.cdn(),
    expires,
    null
);
// https://img.imageboss.me/mysecureimages/cdn/width/500/01.jpg?bossToken=...&expires=...

Srcset generation

Fixed-dimension (DPR) srcset:

String srcset = client.createDprSrcset(
    "examples/02.jpg",
    Operation.cover(300, 300),
    true // variable quality
);

Fluid-width srcset:

String srcset = client.createWidthSrcset(
    "examples/02.jpg",
    Operation.cdn(),
    300,
    1600,
    0.08
);

Kotlin usage

val client = ImageBossClient.newBuilder("mywebsite-images")
    .secret("my-secret")
    .build()

val url = client.createUrl(
    "examples/02.jpg",
    Operation.cdn(),
    Option.formatAuto()
)

Playground

There is a small Java playground you can use to experiment with URLs and srcsets:

# Compile and run tests/build first (so classes are on the classpath)
gradle test

# Then run the playground from your IDE, or from the CLI, e.g.:
java -cp build/classes/java/main:build/classes/java/test me.imageboss.Playground

Edit src/test/java/me/imageboss/Playground.java to try different sources, operations, options, and custom domains (e.g. baseUrl("https://images.example.com")), and inspect the printed URLs/srcsets.

Releasing a new version

See RELEASING.md for detailed instructions and the one-command release script.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors