-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareFiles.java
More file actions
52 lines (45 loc) · 1.83 KB
/
Copy pathCompareFiles.java
File metadata and controls
52 lines (45 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import com.api2convert.Api2Convert;
import com.api2convert.http.Config;
import com.api2convert.model.Job;
import com.api2convert.model.OutputFile;
import java.util.List;
import java.util.Map;
/**
* Guide: Compare Files — visually diff two images (SSIM).
*
* <p>Run (SDK + Jackson on the classpath):
* <pre>
* API2CONVERT_API_KEY=your-key java -cp "target/classes:libs/*" CompareFiles
* </pre>
*/
public final class CompareFiles {
private static final String REMOTE_JPG =
"https://example-files.online-convert.com/raster%20image/jpg/example.jpg";
private static final String REMOTE_JPG_SMALL =
"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg";
public static void main(String[] args) {
Api2Convert client = newClient();
Job job = client.jobs().create(Map.of(
"process", true,
"input", List.of(
Map.of("type", "remote", "source", REMOTE_JPG_SMALL),
Map.of("type", "remote", "source", REMOTE_JPG)),
"conversion", List.of(Map.of(
"category", "operation",
"target", "compare-image",
"options", Map.of("method", "ssim", "threshold", 5, "diff_color", "red")))));
Job done = client.jobs().await(job.id());
System.out.println("Status: " + done.status().code());
for (OutputFile output : done.output()) {
System.out.println("Diff: " + output.uri());
}
}
private static Api2Convert newClient() {
String base = System.getenv("API2CONVERT_BASE_URL");
return base != null && !base.isEmpty()
? new Api2Convert("", Config.builder().baseUrl(base).build())
: new Api2Convert("");
}
private CompareFiles() {
}
}