1 | <?php |
||
11 | class Jetpack_Photon_Image { |
||
12 | |||
13 | /** |
||
14 | * @var string $filename Attachment's Filename. |
||
15 | */ |
||
16 | public $filename; |
||
17 | |||
18 | /** |
||
19 | * @var string/WP_Erorr $mime_type Attachment's mime-type, WP_Error on failure when recalculating the dimensions. |
||
|
|||
20 | */ |
||
21 | private $mime_type; |
||
22 | |||
23 | /** |
||
24 | * @var int $original_width Image original width. |
||
25 | */ |
||
26 | private $original_width; |
||
27 | |||
28 | /** |
||
29 | * @var int $original_width Image original height. |
||
30 | */ |
||
31 | private $original_height; |
||
32 | |||
33 | /** |
||
34 | * @var int $width Current attachment's width. |
||
35 | */ |
||
36 | private $width; |
||
37 | |||
38 | /** |
||
39 | * @var int $height Current attachment's height. |
||
40 | */ |
||
41 | private $height; |
||
42 | |||
43 | /** |
||
44 | * @var bool $is_resized Whether the attachment has been resized yet, or not. |
||
45 | */ |
||
46 | private $is_resized = false; |
||
47 | |||
48 | /** |
||
49 | * Constructs the image object. |
||
50 | * |
||
51 | * The $data array should provide at least |
||
52 | * file : string Image file path |
||
53 | * width : int Image width |
||
54 | * height : int Image height |
||
55 | * |
||
56 | * @param array $data Array of attachment metadata, typically value of _wp_attachment_metadata postmeta |
||
57 | * @param string|\WP_Error $mime_type Typically value returned from get_post_mime_type function. |
||
58 | */ |
||
59 | public function __construct( $data, $mime_type ) { |
||
65 | |||
66 | /** |
||
67 | * Resizes the image to given size. |
||
68 | * |
||
69 | * @param array $size_data Array of width, height, and crop properties of a size. |
||
70 | * |
||
71 | * @return bool|\WP_Error True if resize was successful, WP_Error on failure. |
||
72 | */ |
||
73 | public function resize( $size_data ) { |
||
89 | |||
90 | /** |
||
91 | * Generates size data for usage in $metadata['sizes'];. |
||
92 | * |
||
93 | * @param array $size_data Array of width, height, and crop properties of a size. |
||
94 | * |
||
95 | * @return array|\WP_Error An array containing file, width, height, and mime-type keys and it's values. WP_Error on failure. |
||
96 | */ |
||
97 | public function get_size( $size_data ) { |
||
112 | |||
113 | /** |
||
114 | * Resets the image to it's original dimensions. |
||
115 | * |
||
116 | * @return bool True on successful reset to original dimensions. |
||
117 | */ |
||
118 | public function reset_to_original() { |
||
125 | |||
126 | /** |
||
127 | * Return the basename filename. If the image has been resized, including |
||
128 | * the resizing params for Jetpack CDN. |
||
129 | * |
||
130 | * @return string Basename of the filename. |
||
131 | */ |
||
132 | public function get_filename() { |
||
135 | |||
136 | /** |
||
137 | * Return the absolute filename. If the image has been resized, including |
||
138 | * the resizing params for Jetpack CDN. |
||
139 | * |
||
140 | * @return string Filename. |
||
141 | */ |
||
142 | public function get_raw_filename() { |
||
145 | |||
146 | /** |
||
147 | * Returns current image width. Either original, or after resize. |
||
148 | * |
||
149 | * @return int |
||
150 | */ |
||
151 | public function get_width() { |
||
154 | |||
155 | /** |
||
156 | * Returns current image height. Either original, or after resize. |
||
157 | * |
||
158 | * @return int |
||
159 | */ |
||
160 | public function get_height() { |
||
163 | |||
164 | /** |
||
165 | * Returns image mime type. |
||
166 | * |
||
167 | * @return string|WP_Error Image's mime type or WP_Error if it was not determined. |
||
168 | */ |
||
169 | public function get_mime_type() { |
||
172 | |||
173 | /** |
||
174 | * Checks the resize status of the image. |
||
175 | * |
||
176 | * @return bool If the image has been resized. |
||
177 | */ |
||
178 | public function is_resized() { |
||
181 | |||
182 | /** |
||
183 | * Get filename with proper args for the Photon service. |
||
184 | * |
||
185 | * @return string Filename with query args for Photon service |
||
186 | */ |
||
187 | protected function get_resized_filename() { |
||
200 | |||
201 | /** |
||
202 | * Get resize dimensions used for the Jetpack CDN service. |
||
203 | * |
||
204 | * Converts the list of values returned from `image_resize_dimensions()` to |
||
205 | * associative array for the sake of more readable code no relying on index |
||
206 | * nor `list`. |
||
207 | * |
||
208 | * @param int $max_width |
||
209 | * @param int $max_height |
||
210 | * @param bool|array $crop |
||
211 | * |
||
212 | * @return array|\WP_Error Array of dimensions matching the parameters to imagecopyresampled. WP_Error on failure. |
||
213 | */ |
||
214 | protected function image_resize_dimensions( $max_width, $max_height, $crop ) { |
||
234 | |||
235 | /** |
||
236 | * Sets proper width and height from dimensions. |
||
237 | * |
||
238 | * @param array $dimensions an array of image dimensions. |
||
239 | * @return void |
||
240 | */ |
||
241 | protected function set_width_height( $dimensions ) { |
||
245 | |||
246 | } |
||
247 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.