forked from filestack/filestack-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverting-file-formats.php
54 lines (44 loc) · 1.54 KB
/
converting-file-formats.php
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
<?php
use Filestack\FilestackClient;
use Filestack\FilestackSecurity;
use Filestack\Filelink;
use Filestack\FilestackException;
$test_api_key = 'YOUR_FILESTACK_API_KEY';
$test_secret = 'YOUR_FILESTACK_SECURITY_SECRET';
$source = 'https://www.wikipedia.org/portal/wikipedia.org/' .
'assets/img/[email protected]';
/**
* You can create convert a filelink or url from one format to another,
* to see the list of formats, go to :
* https://www.filestack.com/docs/image-transformations/conversion
*/
$security = new FilestackSecurity($test_secret);
$client = new FilestackClient($test_api_key, $security);
$output_options = [
'background' => 'white',
'density' => 50,
'compress' => true,
'colorspace' => 'input',
'quality' => 80,
'strip' => true,
'pageformat' => 'letter',
'pageorientation' => 'landscape'
];
$filelink = $client->convertFile($source, 'pdf', $output_options);
$destination = __DIR__ . '/../tests/testfiles/convert-file-test.pdf';
$result = $filelink->download($destination);
# or
$contents = $filelink->getContent();
file_put_contents($destination, $contents);
/**
* Or you can convert using a filelink object
*/
$filelink = $client->upload($test_filepath);
$converted_filelink = $filelink->convertFile($source, 'pdf', $output_options);
$destination = __DIR__ . '/../tests/testfiles/convert-filelink-test.pdf';
$result = $converted_filelink->download($destination);
# or
$contents = $converted_filelink->getContent();
file_put_contents($destination, $contents);
// delete remote file
$filelink->delete();