PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.2.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.2.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / classes / Optimization / Process / ProcessInterface.php

ProcessInterface.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.2.2, at classes/Optimization/Process/ProcessInterface.php

294 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace Imagify\Optimization\Process;
5
6 /**
7 * Interface to use to optimize medias.
8 *
9 * @since 1.9
10 */
11 interface ProcessInterface {
12
13 /**
14 * Tell if the given entry can be accepted in the constructor.
15 * For example it can include `is_numeric( $id )` if the constructor accepts integers.
16 *
17 * @since 1.9
18 *
19 * @param mixed $id Whatever.
20 *
21 * @return bool
22 */
23 public static function constructor_accepts( $id );
24
25 /**
26 * Get the data instance.
27 *
28 * @since 1.9
29 *
30 * @return DataInterface|false
31 */
32 public function get_data();
33
34 /**
35 * Get the media instance.
36 *
37 * @since 1.9
38 *
39 * @return MediaInterface|false
40 */
41 public function get_media();
42
43 /**
44 * Get the File instance of the original file.
45 *
46 * @since 1.9.8
47 *
48 * @return File|false
49 */
50 public function get_original_file();
51
52 /**
53 * Get the File instance of the full size file.
54 *
55 * @since 1.9.8
56 *
57 * @return File|false
58 */
59 public function get_fullsize_file();
60
61 /**
62 * Tell if the current media is valid.
63 *
64 * @since 1.9
65 *
66 * @return bool
67 */
68 public function is_valid();
69
70 /**
71 * Tell if the current user is allowed to operate Imagify in this context.
72 *
73 * @since 1.9
74 *
75 * @param string $describer Capacity describer. See \Imagify\Context\ContextInterface->get_capacity() for possible values. Can also be a "real" user capacity.
76 *
77 * @return bool
78 */
79 public function current_user_can( $describer );
80
81 /**
82 * Optimize a media files by pushing tasks into the queue.
83 *
84 * @since 1.9
85 *
86 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
87 *
88 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
89 */
90 public function optimize( $optimization_level = null );
91
92 /**
93 * Re-optimize a media files with a different level.
94 *
95 * @since 1.9
96 *
97 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
98 *
99 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
100 */
101 public function reoptimize( $optimization_level = null );
102
103 /**
104 * Optimize several file sizes by pushing tasks into the queue.
105 *
106 * @since 1.9
107 *
108 * @param array $sizes An array of media sizes (strings). Use "full" for the size of the main file.
109 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
110 *
111 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
112 */
113 public function optimize_sizes( $sizes, $optimization_level = null );
114
115 /**
116 * Optimize one file with Imagify directly.
117 *
118 * @since 1.9
119 *
120 * @param string $size The media size.
121 * @param int $optimization_level The optimization level (0=normal, 1=aggressive, 2=ultra).
122 *
123 * @return array|WP_Error The optimization data. A \WP_Error instance on failure.
124 */
125 public function optimize_size( $size, $optimization_level = null );
126
127 /**
128 * Restore the media files from the backup file.
129 *
130 * @since 1.9
131 *
132 * @return bool|WP_Error True on success. A \WP_Error instance on failure.
133 */
134 public function restore();
135
136 /**
137 * Get the sizes for this media that have not get through optimization.
138 * No sizes are returned if the file is not optimized, has no backup, or is not an image.
139 * The 'full' size os never returned.
140 *
141 * @since 1.9
142 *
143 * @return array|WP_Error {
144 * A WP_Error object on failure.
145 * An array of data for the thumbnail sizes on success.
146 * Size names are used as array keys.
147 *
148 * @type int $width The image width.
149 * @type int $height The image height.
150 * @type bool $crop True to crop, false to resize.
151 * @type string $name The size name.
152 * @type string $file The name the thumbnail "should" have.
153 * }
154 */
155 public function get_missing_sizes();
156
157 /**
158 * Optimize missing thumbnail sizes.
159 *
160 * @since 1.9
161 *
162 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
163 */
164 public function optimize_missing_thumbnails();
165
166 /**
167 * Delete the backup file.
168 *
169 * @since 1.9
170 */
171 public function delete_backup();
172
173 /**
174 * Maybe resize an image.
175 *
176 * @since 1.9
177 *
178 * @param string $size The size name.
179 * @param File $file A File instance.
180 *
181 * @return array|WP_Error A \WP_Error instance on failure, an array on success as follow: {
182 * @type bool $resized True when the image has been resized.
183 * @type bool $backuped True when the image has been backuped.
184 * @type int $file_size The file size in bytes.
185 * }
186 */
187 public function maybe_resize( $size, $file );
188
189 /**
190 * Generate next-gen images if they are missing.
191 *
192 * @since 1.9
193 *
194 * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure.
195 */
196 public function generate_nextgen_versions();
197
198 /**
199 * Delete the next gen format images.
200 * This doesn't delete the related optimization data.
201 *
202 * @since 2.2
203 *
204 * @param bool $keep_full Set to true to keep the full size.
205 *
206 * @return bool|WP_Error True on success. A \WP_Error object on failure.
207 */
208 public function delete_nextgen_files( $keep_full = false );
209
210 /**
211 * Tell if a thumbnail size is an "Imagify Next-Gen" size.
212 *
213 * @since 2.2
214 *
215 * @param string $size_name The size name.
216 *
217 * @return string|bool The unsuffixed name of the size if next-gen. False if not next-gen.
218 */
219 public function is_size_next_gen( $size_name );
220
221 /**
222 * Tell if the media has all next-gen versions.
223 *
224 * @return bool
225 */
226 public function is_full_next_gen();
227
228 /**
229 * Tell if the media has a next-gen format.
230 *
231 * @since 2.2
232 *
233 * @return bool
234 */
235 public function has_next_gen();
236
237 /**
238 * Tell if a process is running for this media.
239 *
240 * @since 1.9
241 *
242 * @return bool
243 */
244 public function is_locked();
245
246 /**
247 * Set the running status to "running" for a period of time.
248 *
249 * @since 1.9
250 */
251 public function lock();
252
253 /**
254 * Delete the running status.
255 *
256 * @since 1.9
257 */
258 public function unlock();
259
260 /**
261 * Tell if a size already has optimization data.
262 *
263 * @since 1.9
264 *
265 * @param string $size The size name.
266 *
267 * @return bool
268 */
269 public function size_has_optimization_data( $size );
270
271 /**
272 * Update the optimization data for a size.
273 *
274 * @since 1.9
275 *
276 * @param object $response The API response.
277 * @param string $size The size name.
278 * @param int $level The optimization level (0=normal, 1=aggressive, 2=ultra).
279 *
280 * @return array {
281 * The optimization data.
282 *
283 * @type string $size The size name.
284 * @type int $level The optimization level.
285 * @type string $status The status: 'success', 'already_optimized', 'error'.
286 * @type bool $success True if successfully optimized. False on error or if already optimized.
287 * @type string $error An error message.
288 * @type int $original_size The weight of the file, before optimization.
289 * @type int $optimized_size The weight of the file, once optimized.
290 * }
291 */
292 public function update_size_optimization_data( $response, $size, $level );
293 }
294