Skip to content

Latest commit

 

History

History
69 lines (53 loc) · 2.44 KB

File metadata and controls

69 lines (53 loc) · 2.44 KB

imgproxy-java

logo

build Maven Central

fluently generate asset urls for img-proxy within java

  • dependency-free at runtime
  • requires Java 11+
  • supports signed and unsigned imgproxy URLs
  • supports official imgproxy hex key/salt configuration
  • supports both encoded and /plain/ source URLs

example usage

// unsigned
String url = Signature.of(SignatureConfiguration.unsigned(BASE_URL))
                .size(300, 300)
                .url(SOURCE_URL)

configuration

// official imgproxy configuration:
// key and salt are the hex-encoded values from IMGPROXY_KEY / IMGPROXY_SALT
SignatureConfiguration signedConfiguration = SignatureConfiguration.signed(
                imgproxyProperties.getBaseurl(),
                imgproxyProperties.getKey(),
                imgproxyProperties.getSalt());

// raw/plain-text fallback:
// only use this if you already have raw key/salt bytes
SignatureConfiguration rawConfiguration = SignatureConfiguration.signedRaw(
                imgproxyProperties.getBaseurl(),
                keyBytes,
                saltBytes);

further usages

String resizedUrl = Signature.of(signedConfiguration)
                .resize(ResizeType.fit, 300, 300, true)
                .url("s3://bucket-name/" + assetReference.getUrlPath());

// exact 75x75 thumbnail, cropped around the smart focal area
String thumbUrl = Signature.of(signedConfiguration)
                .resize(ResizeType.fill, 75, 75, false, false)
                .gravity(GravityType.sm)
                .url("s3://bucket-name/path/image.jpg", ImageType.webp);

// keep the whole image visible inside 300x300 and fill the remaining area with white
String containUrl = Signature.of(signedConfiguration)
                .resize(ResizeType.fit, 300, 300, false, true)
                .background("FFFFFF")
                .url("s3://bucket-name/path/image.jpg", ImageType.webp);

// useful if you don't want the source URL base64-encoded in the path
String plainUrl = Signature.of(signedConfiguration)
                .resize(ResizeType.fit, 1200, 800, true)
                .quality(85)
                .urlPlain("https://cdn.example.org/images/photo.jpg?version=42", ImageType.jpg);