PluginProbe ʕ •ᴥ•ʔ
TinyPNG – JPEG, PNG & WebP image compression / 3.8.0
TinyPNG – JPEG, PNG & WebP image compression v3.8.0
3.8.0 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 / Source.php
tiny-compress-images / src / vendor / tinify / Tinify Last commit date
Client.php 6 months ago Exception.php 4 years ago Result.php 4 years ago ResultMeta.php 1 year ago Source.php 6 months ago
Source.php
83 lines
1 <?php
2
3 namespace Tinify;
4
5 class Source {
6 private $url, $commands;
7
8 public static function fromFile($path) {
9 return self::fromBuffer(file_get_contents($path));
10 }
11
12 public static function fromBuffer($string) {
13 $response = Tinify::getClient()->request("post", "/shrink", $string);
14 return new self($response->headers["location"]);
15 }
16
17 public static function fromUrl($url) {
18 $body = array("source" => array("url" => $url));
19 $response = Tinify::getClient()->request("post", "/shrink", $body);
20 return new self($response->headers["location"]);
21 }
22
23 public function __construct($url, $commands = array()) {
24 $this->url = $url;
25 $this->commands = $commands;
26 }
27
28 public function preserve() {
29 $options = $this->flatten(func_get_args());
30 $commands = array_merge($this->commands, array("preserve" => $options));
31 return new self($this->url, $commands);
32 }
33
34 public function resize($options) {
35 $commands = array_merge($this->commands, array("resize" => $options));
36 return new self($this->url, $commands);
37 }
38
39 public function store($options) {
40 $response = Tinify::getClient()->request("post", $this->url,
41 array_merge($this->commands, array("store" => $options)));
42 return new Result($response->headers, $response->body);
43 }
44
45 public function convert($options) {
46 $commands = array_merge($this->commands, array("convert" => $options));
47 return new self($this->url, $commands);
48 }
49
50 public function transform($options) {
51 $commands = array_merge($this->commands, array("transform" => $options));
52 return new self($this->url, $commands);
53 }
54
55 public function result() {
56 $has_commands = !empty($this->commands);
57 $method = $has_commands ? "post" : "get";
58 $body = $has_commands ? $this->commands : null;
59 $response = Tinify::getClient()->request($method, $this->url, $body);
60 return new Result($response->headers, $response->body);
61 }
62
63 public function toFile($path) {
64 return $this->result()->toFile($path);
65 }
66
67 public function toBuffer() {
68 return $this->result()->toBuffer();
69 }
70
71 private static function flatten($options) {
72 $flattened = array();
73 foreach ($options as $option) {
74 if (is_array($option)) {
75 $flattened = array_merge($flattened, $option);
76 } else {
77 array_push($flattened, $option);
78 }
79 }
80 return $flattened;
81 }
82 }
83