-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathclient-transformations.php
52 lines (42 loc) · 1.52 KB
/
client-transformations.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
<?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';
$test_filepath = __DIR__ . '/../tests/testfiles/calvinandhobbes.jpg';
# Filestack client examples
$security = new FilestackSecurity($test_secret);
$client = new FilestackClient($test_api_key, $security);
// transformations
$transformed_file = $client->transform($filelink->handle, $transform_tasks);
# or
$transformed_file = $client->transform($url, $transform_tasks);
$destination = __DIR__ . '/../tests/testfiles/my-transformed-file.png';
$contents = $transformed_file->getContent();
file_put_contents($destination, $contents);
# or
$result = $transformed_file->download($destination);
// zipping files
$sources = [
'https://d1wtqaffaaj63z.cloudfront.net/images/20150617_143146.jpg',
$filelink->handle
];
$zipped_filelink = $client->zip($sources);
$destination = __DIR__ . '/../tests/testfiles/contents-zipped.zip';
$result = $zipped_filelink->download($destination);
# or
$contents = $zipped_filelink->getContent();
file_put_contents($destination, $contents);
// debugging transformation calls
$transform_tasks = [
'resize' => ['w' => '100', 'h' => '100'],
'detect_faces' => []
];
/**
* calling debug() will return a json item detailing
* any errors the tasks may return
*/
$json_response = $client->debug($this->test_file_handle, $transform_tasks);
print_r($json_response);