Repository navigation
Expand file tree
/
Copy pathphp_quickstart.php
More file actions
76 lines (56 loc) · 1.68 KB
/
Copy pathphp_quickstart.php
File metadata and controls
76 lines (56 loc) · 1.68 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html lang="HTML5">
<head>
<title>PHP Quick Start</title>
</head>
<body>
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Cloudinary\Configuration\Configuration;
use Cloudinary\Api\Upload\UploadApi;
use Cloudinary\Api\Admin\AdminApi;
use Cloudinary\Tag\ImageTag;
use Cloudinary\Transformation\Background;
use Cloudinary\Transformation\Resize;
echo '<h1>Cloudinary PHP Quick Start</h1>';
// replace `cloudinary://my_key:my_secret@my_cloud_name` with your environment variable
Configuration::instance('cloudinary://my_key:my_secret@my_cloud_name?secure=true');
// Upload API
echo '<h2>Upload API Response</h2>';
// Upload the image
$upload = new UploadApi();
echo '<pre>';
echo json_encode(
$upload->upload('https://res.cloudinary.com/demo/image/upload/flower.jpg', [
'public_id' => 'flower_sample',
'use_filename' => TRUE,
'overwrite' => TRUE]),
JSON_PRETTY_PRINT
);
echo '</pre>';
// Admin api
echo '<h2>Admin API Response</h2>';
// Get the asset details
$admin = new AdminApi();
echo '<pre>';
echo json_encode($admin->asset('flower_sample', [
'colors' => TRUE]), JSON_PRETTY_PRINT
);
echo '</pre>';
// Delivery with transformations
echo '<h2>Cloudinary Image</h2>';
// Create the image tag with the transformed image
$imgtag = (new ImageTag('flower_sample'))
->resize(Resize::pad()
->width(400)
->height(400)
->background(Background::predominant())
);
echo $imgtag;
// The code above generates the following HTML image tag (for the demo account):
// <img src="https://res.cloudinary.com/demo/image/upload/b_auto:predominant,c_pad,h_400,w_400/flower_sample">
echo '<br>';
echo '<br>';
echo '<br>';
?>
</body>
</html>