-
Notifications
You must be signed in to change notification settings - Fork 26
/
convert_to_webp.js
41 lines (37 loc) · 1.02 KB
/
convert_to_webp.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
// Run this file as:
//
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node examples/convert_to_webp.js ./fixtures/berkley.jpg
//
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
const Transloadit = require('../src/Transloadit')
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY,
authSecret: process.env.TRANSLOADIT_SECRET,
})
const filePath = process.argv[2]
;(async () => {
try {
const opts = {
files: {
file1: filePath,
},
params: {
steps: {
webp: {
use: ':original',
robot: '/image/resize',
result: true,
imagemagick_stack: 'v2.0.7',
format: 'webp',
},
},
},
waitForCompletion: true,
}
const status = await transloadit.createAssembly(opts)
console.log('Your WebP file:', status.results.webp[0].url)
} catch (err) {
console.error('createAssembly failed', err)
}
})()