-
Benachrichtigungen
You must be signed in to change notification settings - Fork 74
/
App.js
260 lines (248 loc) · 10.1 KB
/
App.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import { Cloudinary } from '@cloudinary/url-gen';
import { pad } from '@cloudinary/url-gen/actions/resize';
import { generativeFill } from '@cloudinary/url-gen/qualifiers/background';
import './App.css';
import images from './images.json';
const cld = new Cloudinary({
cloud: {
cloudName: process.env.REACT_APP_CLOUDINARY_CLOUD_NAME
}
});
const PUBLIC_ID_BACKGROUND = 'examples/galaxy_sqrqb2';
function App() {
return (
<main className="main">
<div className="container">
<h1 className="title">
Cloudinary React SDK AdvancedImage Component
</h1>
</div>
<div className="container">
<h2>Optimization</h2>
<p>Format of auto (<code>f_auto</code>) and quality of auto (<code>q_auto</code>).</p>
<ul className="images">
{images.slice(0, 4).map(image => {
const imgSrc = cld.image(image.image)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
</div>
<div className="container">
<h2>AI Generative Fill</h2>
<p>Original</p>
<ul className="images">
{[images[0], images[2], images[4], images[8]].map(image => {
const imgSrc = cld.image(image.image)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>With Generative Fill</p>
<ul className="images">
{[images[0], images[2], images[4], images[8]].map(image => {
const imgSrc = cld.image(image.image)
.resize(
pad()
.width(1200)
.height(1800)
.background(generativeFill())
)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width={1200} height={1200} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
</div>
<div className="container">
<h2>Background Removal</h2>
<p>On-the-fly background removal (<code>e_background_removal</code>).</p>
<ul className="images">
{images.slice(0, 4).map(image => {
const imgSrc = cld.image(image.image)
.effect('e_background_removal')
.resize(`w_${image.width},h_${image.height}`)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>With solid color background.</p>
<ul className="images">
{images.slice(0, 4).map(image => {
const imgSrc = cld.image(image.image)
.effect('e_background_removal')
.resize(`w_${image.width},h_${image.height}`)
.backgroundColor('#692ba8')
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>With an image underlay as the background.</p>
<ul className="images">
{images.slice(0, 4).map(image => {
const imgSrc = cld.image(image.image)
.effect(`e_background_removal`)
.resize(`w_${image.width},h_${image.height}`)
.effect(`u_${PUBLIC_ID_BACKGROUND.replaceAll('/', ':')},c_fill,w_${image.width},h_${image.height}`)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
</div>
<div className="container">
<h2>Pan & Zoom</h2>
<p>Zoom into the center of an image (<code>e_panzoom</code>).</p>
<ul className="images">
{images.filter(({ id }) => ['girl', 'parrot', 'guitar-player', 'model'].includes(id)).map(image => {
const imgSrc = cld.image(image.image)
.resize(`w_${image.width},h_${image.height}`)
.effect('e_zoompan')
.quality('auto')
.format('gif')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>With looping (<code>e_panzoom/e_loop</code>).</p>
<ul className="images">
{images.filter(({ id }) => ['girl', 'parrot', 'guitar-player', 'model'].includes(id)).map(image => {
const imgSrc = cld.image(image.image)
.resize(`w_${image.width},h_${image.height}`)
.quality('auto')
.effect('e_zoompan')
.effect('e_loop')
.format('gif')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>With zooming automatically to the subject (<code>e_zoompan:to_(g_auto)</code>)</p>
<ul className="images">
{images.filter(({ id }) => ['girl', 'parrot', 'guitar-player', 'model'].includes(id)).map(image => {
const imgSrc = cld.image(image.image)
.resize(`w_${image.width},h_${image.height}`)
.effect('e_zoompan:to_(g_auto)')
.effect('e_loop')
.quality('auto')
.format('gif')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>With lower FPS (<code>e_panzoom,fps_2</code>)</p>
<ul className="images">
{images.filter(({ id }) => ['girl', 'parrot', 'guitar-player', 'model'].includes(id)).map(image => {
const imgSrc = cld.image(image.image)
.resize(`w_${image.width},h_${image.height}`)
.effect('e_zoompan:fps_2')
.effect('e_loop')
.quality('auto')
.format('gif')
.toURL();
return (
<li key={image.id}>
<img width={image.width} height={image.height} src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
</div>
<div className="container">
<h2>Gravity</h2>
<p>Using <code>g_auto</code> to automatically center to the subject.</p>
<ul className="images">
{images.filter(({ id }) => ['girl', 'parrot', 'guitar-player', 'model'].includes(id)).map(image => {
const imgSrc = cld.image(image.image)
.resize(`w_1000,h_1000,c_thumb,g_auto`)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width="500" height="500" src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
<p>Using <code>g_faces</code> (or <code>g_face</code>) to target the subject's face.</p>
<ul className="images">
{images.filter(({ id }) => ['girl', 'parrot', 'guitar-player', 'model'].includes(id)).map(image => {
const imgSrc = cld.image(image.image)
.resize(`w_1000,h_1000,c_thumb,g_face`)
.quality('auto')
.format('auto')
.toURL();
return (
<li key={image.id}>
<img width="500" height="500" src={imgSrc} alt={image.title} loading="lazy" />
</li>
)
})}
</ul>
</div>
<div className="container">
<h2>Resources</h2>
<p>
<a href="https://github.com/colbyfayock/cloudinary-examples/tree/main/examples/react-transformations-effects">See the code on github.com.</a>
</p>
<ul>
{images.slice(0, 4).map(image => {
return (
<li key={image.id}>
{ image.title }: <a href={image.link} rel="noreferrer">{image.link}</a>
</li>
)
})}
</ul>
</div>
</main>
);
}
export default App;