PluginProbe ʕ •ᴥ•ʔ
TinyPNG – JPEG, PNG & WebP image compression / 2.2.4
TinyPNG – JPEG, PNG & WebP image compression v2.2.4
3.7.0 3.6.14 trunk 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.4.0 1.5.0 1.6.0 1.7.0 1.7.1 1.7.2 2.0.0 2.0.1 2.0.2 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.0.0 3.0.1 3.1.0 3.2.0 3.2.1 3.3 3.4 3.4.1 3.4.2 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.10 3.6.11 3.6.12 3.6.13 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9
tiny-compress-images / src / vendor / tinify / Tinify.php
tiny-compress-images / src / vendor / tinify Last commit date
Tinify 9 years ago data 9 years ago Tinify.php 9 years ago
Tinify.php
119 lines
1 <?php
2
3 namespace Tinify;
4
5 const VERSION = "1.5.0";
6
7 class Tinify {
8 const AUTHENTICATED = true;
9 const ANONYMOUS = false;
10
11 private static $key = NULL;
12 private static $appIdentifier = NULL;
13 private static $proxy = NULL;
14
15 private static $compressionCount = NULL;
16
17 private static $client = NULL;
18
19 public static function setKey($key) {
20 self::$key = $key;
21 self::$client = NULL;
22 }
23
24 public static function getKey() {
25 return self::$key;
26 }
27
28 public static function createKey($email, $options) {
29 $body = array_merge(array("email" => $email), $options);
30 $response = self::getClient(self::ANONYMOUS)->request("post", "/keys", $body);
31 self::setKey($response->body->key);
32 }
33
34 public static function setAppIdentifier($appIdentifier) {
35 self::$appIdentifier = $appIdentifier;
36 self::$client = NULL;
37 }
38
39 public static function setProxy($proxy) {
40 self::$proxy = $proxy;
41 self::$client = NULL;
42 }
43
44 public static function getCompressionCount() {
45 return self::$compressionCount;
46 }
47
48 public static function setCompressionCount($compressionCount) {
49 self::$compressionCount = $compressionCount;
50 }
51
52 public static function getClient($mode = self::AUTHENTICATED) {
53 if ($mode == self::AUTHENTICATED && !self::$key) {
54 throw new AccountException("Provide an API key with Tinify\setKey(...)");
55 }
56
57 if (!self::$client) {
58 self::$client = new Client(self::$key, self::$appIdentifier, self::$proxy);
59 }
60
61 return self::$client;
62 }
63
64 public static function setClient($client) {
65 self::$client = $client;
66 }
67 }
68
69 function setKey($key) {
70 return Tinify::setKey($key);
71 }
72
73 function getKey() {
74 return Tinify::getKey();
75 }
76
77 function createKey($email, $options) {
78 return Tinify::createKey($email, $options);
79 }
80
81 function setAppIdentifier($appIdentifier) {
82 return Tinify::setAppIdentifier($appIdentifier);
83 }
84
85 function setProxy($proxy) {
86 return Tinify::setProxy($proxy);
87 }
88
89 function getCompressionCount() {
90 return Tinify::getCompressionCount();
91 }
92
93 function compressionCount() {
94 return Tinify::getCompressionCount();
95 }
96
97 function fromFile($path) {
98 return Source::fromFile($path);
99 }
100
101 function fromBuffer($string) {
102 return Source::fromBuffer($string);
103 }
104
105 function fromUrl($string) {
106 return Source::fromUrl($string);
107 }
108
109 function validate() {
110 try {
111 Tinify::getClient()->request("post", "/shrink");
112 } catch (AccountException $err) {
113 if ($err->status == 429) return true;
114 throw $err;
115 } catch (ClientException $err) {
116 return true;
117 }
118 }
119