Image proxy server based on spring cloud gateway filters provides opportunity to modify images on fly.
There are two ways to customize response image:
- By passing additional query parameter at the request, see tables below
- By setting up default filters parameters at the spring application properties
It is available to use several filters for a specific url and enable an image filter by customizing settings of proxied server
response (see io.github.aptushkin.proxy.image.modify.predicate.ImageModifierPredicate and responseHeaderName property).
Usage:
- As standalone http (https in todo list) proxy server to modify image responses from proxied servers
- As dependency, it is possible to fetch proxy-image-starterto get image modifications filters for your custom spring cloud gateway server
- TODO: As part of spring cloud microservices infrastructure (eureka, config server)
- TODO: As part of your Spring REST API server by fetching a starter
Fetch dependency from https://repo1.maven.org/maven2:
Maven:
<dependency>
    <groupId>io.github.artemptushkin.proxy.image</groupId>
    <artifactId>proxy-image-starter</artifactId>
    <version>1.0.3</version>
</dependency>Gradle:
compile group: 'io.github.aptushkin.proxy.image', name: 'proxy-image-starter', version: '0.0.1-SNAPSHOT'Use spring properties to activate custom image filters:
proxy.image:
    enalbed: true- 
Enable default filter to proxy every request to the target destination spring: cloud: gateway: default-filters: - ProxyForward
- 
Customize routing properties to specify image modification filters spring.cloud.gateway.routes: - id: modify_image_router uri: no://op predicates: - Path=/** 
- 
Specify required filters spring.cloud.gateway: filters: name: ModifyImageSize args: responseHeaderName: Content-Type regexp: image/.* 
Spring properties name: ResizeImage
Default properties:
| Property | Required | Description | 
|---|---|---|
| defaultWidth | N | Default width value of resize method | 
| defaultHeight | N | Default height value of resize method | 
| defaultMode | N | Default mode value of resize method; See http://javadox.com/org.imgscalr/imgscalr-lib/4.2/org/imgscalr/Scalr.Mode.html | 
| defaultMethod | N | Default method value of resize method; http://javadox.com/org.imgscalr/imgscalr-lib/4.2/org/imgscalr/Scalr.Method.html | 
| responseHeaderName | Y | The header name of proxied server response | 
| regexp | Y | Regex to verify response header value. If matched then current filter should be applied | 
| onNotExistedHeader | N | If true, current filter will be applied; otherwise not | 
| defaultFormat | N | default file format for image modification | 
Query parameters:
| Property | Description | 
|---|---|
| width | Width value of target image | 
| height | Height value of target image | 
| format | File format for image modification | 
| mode | Mode value of resize method; See http://javadox.com/org.imgscalr/imgscalr-lib/4.2/org/imgscalr/Scalr.Mode.html | 
| method | Method value of resize method; See http://javadox.com/org.imgscalr/imgscalr-lib/4.2/org/imgscalr/Scalr.Mode.html | 
Curl example:
curl --location --request GET 'http://github.githubassets.com/images/modules/open_graph/github-octocat.png?width=100&height=300&format=jpg'
Spring properties name: CropImage
Default properties:
| Property | Required | Description | 
|---|---|---|
| defaultWidth | N | Default width value of crop method | 
| defaultHeight | N | Default height value of crop method | 
| defaultX | N | Default X value of crop method; Used to crop the proxy image from the top-left corner | 
| defaultY | N | Default Y value of crop method; Used to crop the proxy image from the top-left corner | 
| responseHeaderName | Y | The header name of proxied server response | 
| regexp | Y | Regex to verify response header value. If matched then current filter should be applied | 
| onNotExistedHeader | N | If true, current filter will be applied; otherwise not | 
| defaultFormat | N | default file format for image modification | 
Query parameters:
| Property | Description | 
|---|---|
| width | Width value of target image | 
| height | Height value of target image | 
| format | File format for image modification | 
| x | X value of crop method; Used to crop the proxy image from the top-left corner | 
| y | Y value of crop method; Used to crop the proxy image from the top-left corner | 
Curl example:
curl --location --request GET 'http://github.githubassets.com/images/modules/open_graph/github-octocat.png?width=600&height=500&x=400&y=100&format=jpg'
Spring properties name: RotateImage
Default properties:
| Property | Required | Description | 
|---|---|---|
| rotation | N | Default rotation value for rotation method; See http://javadox.com/org.imgscalr/imgscalr-lib/4.2/org/imgscalr/Scalr.Rotation.html | 
| responseHeaderName | Y | The header name of proxied server response | 
| regexp | Y | Regex to verify response header value. If matched then current filter should be applied | 
| onNotExistedHeader | N | If true, current filter will be applied; otherwise not | 
| defaultFormat | N | default file format for image modification | 
Query parameters:
| Property | Description | 
|---|---|
| rotation | Rotation value for rotation method; See http://javadox.com/org.imgscalr/imgscalr-lib/4.2/org/imgscalr/Scalr.Rotation.html | 
| format | File format for image modification | 
Curl example:
curl --location --request GET 'http://github.githubassets.com/images/modules/open_graph/github-octocat.png?rotation=CW_180'
mvn clean install
Run proxy server with classpath config file
java -jar ./proxy-image-server/target/proxy-image-server-0.0.1-SNAPSHOT.jar
mvn clean deploy
mvn clean release:prepare release:perform -Prelease
- Enabled HTTPS proxy requests for image-server
- Make starter for common web applications to use it with internal response filters for a specific url
- To add dependencies of spring cloud infrastructure: eureka-client, config-client