-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
59 lines (44 loc) · 1.89 KB
/
Main.java
File metadata and controls
59 lines (44 loc) · 1.89 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
53
54
55
56
57
58
59
package org.example;
// Import the required packages
import com.cloudinary.*;
import com.cloudinary.utils.ObjectUtils;
import io.github.cdimascio.dotenv.Dotenv;
import java.util.Map;
public class Main {
public static void main(String[] args) {
// Set your Cloudinary credentials
Dotenv dotenv = Dotenv.load();
Cloudinary cloudinary = new Cloudinary(dotenv.get("CLOUDINARY_URL"));
cloudinary.config.secure = true;
System.out.println(
cloudinary.config.cloudName);
try {
// Upload the image
Map params1 = ObjectUtils.asMap(
"use_filename", true,
"unique_filename", false,
"overwrite", true
);
System.out.println(
cloudinary.uploader().upload("https://cloudinary-devs.github.io/cld-docs-assets/assets/images/coffee_cup.jpg", params1));
// Get the asset details
Map params2 = ObjectUtils.asMap(
"quality_analysis", true
);
System.out.println(
cloudinary.api().resource("coffee_cup", params2));
// Create the image tag with the transformed image and log it to the console
System.out.println(
cloudinary.url().transformation(new Transformation()
.crop("pad")
.width(300)
.height(400)
.background("auto:predominant"))
.imageTag("coffee_cup"));
// The code above generates an HTML image tag similar to the following:
// <img src='https://res.cloudinary.com/demo/image/upload/b_auto:predominant,c_pad,h_400,w_300/coffee_cup' height='400' width='300'/>
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}