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 / class-tiny-image.php
tiny-compress-images / src Last commit date
compatibility 2 months ago config 2 months ago css 7 months ago data 4 years ago images 4 years ago js 1 week ago vendor 6 months ago views 1 week ago class-tiny-apache-rewrite.php 2 months ago class-tiny-bulk-optimization.php 2 months ago class-tiny-cli.php 2 months ago class-tiny-compress-client.php 1 week ago class-tiny-compress-fopen.php 2 months ago class-tiny-compress.php 1 week ago class-tiny-conversion.php 4 months ago class-tiny-diagnostics.php 7 months ago class-tiny-exception.php 7 months ago class-tiny-helpers.php 2 months ago class-tiny-image-size.php 1 week ago class-tiny-image.php 1 week ago class-tiny-logger.php 2 months ago class-tiny-migrate.php 2 months ago class-tiny-notices.php 2 months ago class-tiny-php.php 2 months ago class-tiny-picture.php 2 months ago class-tiny-plugin.php 1 week ago class-tiny-settings.php 1 week ago class-tiny-source-base.php 1 week ago class-tiny-source-image.php 7 months ago class-tiny-source-picture.php 7 months ago class-tiny-wp-base.php 2 months ago
class-tiny-image.php
679 lines
1 <?php
2 /*
3 * Tiny Compress Images - WordPress plugin.
4 * Copyright (C) 2015-2018 Tinify B.V.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc., 51
18 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 class Tiny_Image {
22 const ORIGINAL = 0;
23 const ORIGINAL_UNSCALED = 'original_unscaled';
24
25 /** @var Tiny_Settings */
26 private $settings;
27 private $id;
28 private $name;
29 private $wp_metadata;
30 private $sizes = array();
31 private $statistics = array();
32
33 public function __construct(
34 $settings,
35 $id,
36 $wp_metadata = null,
37 $tiny_metadata = null,
38 $active_sizes = null,
39 $active_tinify_sizes = null
40 ) {
41 $this->settings = $settings;
42 $this->id = $id;
43 $this->wp_metadata = $wp_metadata;
44 $this->parse_wp_metadata();
45 $this->parse_tiny_metadata( $tiny_metadata );
46 $this->detect_duplicates( $active_sizes, $active_tinify_sizes );
47 }
48
49 private function parse_wp_metadata() {
50 if ( ! is_array( $this->wp_metadata ) ) {
51 $this->wp_metadata = wp_get_attachment_metadata( $this->id );
52 }
53
54 if ( ! is_array( $this->wp_metadata ) || ! isset( $this->wp_metadata['file'] ) ) {
55 /*
56 No file metadata found, this might be another plugin messing with
57 metadata. Simply ignore this! */
58 return;
59 }
60
61 $upload_dir = wp_upload_dir();
62 $path_prefix = $upload_dir['basedir'] . '/';
63 $path_info = pathinfo( $this->wp_metadata['file'] );
64 if ( isset( $path_info['dirname'] ) ) {
65 $path_prefix .= $path_info['dirname'] . '/';
66 }
67
68 /*
69 Do not use pathinfo for getting the filename.
70 It doesn't work when the filename starts with a special character. */
71 $path_parts = explode( '/', $this->wp_metadata['file'] );
72 $this->name = end( $path_parts );
73 $filename = $path_prefix . $this->name;
74 $this->sizes[ self::ORIGINAL ] = new Tiny_Image_Size( $filename );
75
76 if ( isset( $this->wp_metadata['original_image'] ) ) {
77 $this->sizes[ self::ORIGINAL_UNSCALED ] = new Tiny_Image_Size(
78 $path_prefix . wp_basename( $this->wp_metadata['original_image'] )
79 );
80 }
81
82 // Ensure 'sizes' exists and is an array to prevent PHP Warnings
83 $sizes = isset( $this->wp_metadata['sizes'] ) && is_array( $this->wp_metadata['sizes'] )
84 ? $this->wp_metadata['sizes']
85 : array();
86
87 $sanitized_sizes = array();
88 foreach ( $sizes as $size_name => $size_info ) {
89 // size is valid when its an array and has a file
90 if ( is_array( $size_info ) && isset( $size_info['file'] ) ) {
91 // Add to sanitized metadata
92 $sanitized_sizes[ $size_name ] = $size_info;
93 $this->sizes[ $size_name ] = new Tiny_Image_Size(
94 $path_prefix . wp_basename( $size_info['file'] )
95 );
96 }
97 }
98
99 // Update the metadata with only the valid sizes found
100 $this->wp_metadata['sizes'] = $sanitized_sizes;
101 }
102
103 private function detect_duplicates( $active_sizes, $active_tinify_sizes ) {
104 $filenames = array();
105
106 if ( is_array( $this->wp_metadata )
107 && isset( $this->wp_metadata['file'] )
108 && isset( $this->wp_metadata['sizes'] )
109 && is_array( $this->wp_metadata['sizes'] ) ) {
110
111 if ( null == $active_sizes ) {
112 $active_sizes = $this->settings->get_sizes();
113 }
114 if ( null == $active_tinify_sizes ) {
115 $active_tinify_sizes = $this->settings->get_active_tinify_sizes();
116 }
117
118 foreach ( $this->wp_metadata['sizes'] as $size_name => $size ) {
119 if ( $this->sizes[ $size_name ]->has_been_compressed()
120 && array_key_exists( $size_name, $active_sizes ) ) {
121 $filenames = $this->duplicate_check( $filenames, $size['file'], $size_name );
122 }
123 }
124 foreach ( $this->wp_metadata['sizes'] as $size_name => $size ) {
125 if ( in_array( $size_name, $active_tinify_sizes, true ) ) {
126 $filenames = $this->duplicate_check( $filenames, $size['file'], $size_name );
127 }
128 }
129 foreach ( $this->wp_metadata['sizes'] as $size_name => $size ) {
130 if ( array_key_exists( $size_name, $active_sizes ) ) {
131 $filenames = $this->duplicate_check( $filenames, $size['file'], $size_name );
132 }
133 }
134 foreach ( $this->wp_metadata['sizes'] as $size_name => $size ) {
135 $filenames = $this->duplicate_check( $filenames, $size['file'], $size_name );
136 }
137 }
138 }
139
140 private function duplicate_check( $filenames, $file, $size_name ) {
141 if ( isset( $filenames[ $file ] ) ) {
142 if ( $filenames[ $file ] != $size_name ) {
143 $this->sizes[ $size_name ]->mark_duplicate( $filenames[ $file ] );
144 }
145 } else {
146 $filenames[ $file ] = $size_name;
147 }
148 return $filenames;
149 }
150
151 /**
152 * Will retrieve compression meta data for the given post_id.
153 *
154 * As migrations on large libraries can take longer, we will fall back on
155 * the legacy key on migrating. We can remove the LEGACY_META_KEY on 3.8.0.
156 *
157 * @since 3.7.0
158 *
159 * @param int $post_id Attachment ID.
160 * @return mixed The stored tiny metadata, or '' when none exists.
161 */
162 public static function get_tiny_metadata( $post_id ) {
163 $tiny_metadata = get_post_meta( $post_id, Tiny_Config::META_KEY, true );
164
165 if ( empty( $tiny_metadata ) ) {
166 $tiny_metadata = get_post_meta( $post_id, Tiny_Config::LEGACY_META_KEY, true );
167 }
168
169 return $tiny_metadata;
170 }
171
172 private function parse_tiny_metadata( $tiny_metadata = null ) {
173 if ( is_null( $tiny_metadata ) ) {
174 $tiny_metadata = self::get_tiny_metadata( $this->id );
175 }
176 if ( $tiny_metadata ) {
177 foreach ( $tiny_metadata as $size => $meta ) {
178 if ( ! isset( $this->sizes[ $size ] ) ) {
179 if ( self::is_retina( $size ) && Tiny_Settings::wr2x_active() ) {
180 $size_name = rtrim( $size, '_wr2x' );
181 if ( 'original' === $size_name ) {
182 $size_name = '0';
183 }
184 $retina_path = wr2x_get_retina(
185 $this->sizes[ $size_name ]->filename
186 );
187 $this->sizes[ $size ] = new Tiny_Image_Size( $retina_path );
188 } else {
189 $this->sizes[ $size ] = new Tiny_Image_Size();
190 }
191 }
192 $this->sizes[ $size ]->meta = $meta;
193 }
194 }
195 }
196
197 public function get_id() {
198 return $this->id;
199 }
200
201 public function get_name() {
202 return $this->name;
203 }
204
205 public function get_wp_metadata() {
206 return $this->wp_metadata;
207 }
208
209 public function file_type_allowed() {
210 return in_array(
211 $this->get_mime_type(),
212 array( 'image/jpeg', 'image/png', 'image/webp' ),
213 true
214 );
215 }
216
217 public function get_mime_type() {
218 return get_post_mime_type( $this->id );
219 }
220
221 public function compress() {
222 Tiny_Logger::debug(
223 'compress',
224 array(
225 'image_id' => $this->id,
226 'name' => $this->name,
227 )
228 );
229
230 if ( $this->settings->get_compressor() === null || ! $this->file_type_allowed() ) {
231 return;
232 }
233
234 /**
235 * Fires before an image is sent for compression.
236 *
237 * @since 3.7.0
238 *
239 * @param int $attachment_id The attachment ID
240 */
241 do_action(
242 'tiny_image_before_compression',
243 $this->id
244 );
245
246 $success = 0;
247 $failed = 0;
248
249 $active_tinify_sizes = $this->settings->get_active_tinify_sizes();
250
251 if ( $this->settings->get_conversion_enabled() ) {
252 $uncompressed_sizes = $this->filter_image_sizes( 'uncompressed', $active_tinify_sizes );
253 $unconverted_sizes = $this->filter_image_sizes( 'unconverted', $active_tinify_sizes );
254
255 $unprocessed_sizes = $uncompressed_sizes + $unconverted_sizes;
256 } else {
257 $unprocessed_sizes = $this->filter_image_sizes( 'uncompressed', $active_tinify_sizes );
258 }
259
260 $compressor = $this->settings->get_compressor();
261 $convert_to = $this->convert_to();
262
263 foreach ( $unprocessed_sizes as $size_name => $size ) {
264 if ( ! $size->is_duplicate() ) {
265 $size->add_tiny_meta_start();
266 $this->update_tiny_post_meta();
267
268 $resize = $this->settings->get_resize_options( $size_name );
269 $preserve = $this->settings->get_preserve_options( $size_name );
270 Tiny_Logger::debug(
271 'compress size',
272 array(
273 'image_id' => $this->id,
274 'size' => $size_name,
275 'resize' => $resize,
276 'preserve' => $preserve,
277 'convert' => $convert_to,
278 'modified' => $size->modified(),
279 'filename' => $size->filename,
280 'is_duplicate' => $size->is_duplicate(),
281 'exists' => $size->exists(),
282 'has_been_compressed' => $size->has_been_compressed(),
283 'filesize' => $size->filesize(),
284 'mimetype' => $size->mimetype(),
285 )
286 );
287 try {
288 $response = $compressor->compress_file(
289 $size->filename,
290 $resize,
291 $preserve,
292 $convert_to
293 );
294
295 // ensure that all conversion are in the same format as the first one
296 $convert_to = isset( $response['convert'] ) ?
297 array( $response['convert']['type'] ) :
298 $convert_to;
299
300 $size->add_tiny_meta( $response );
301 ++$success;
302 Tiny_Logger::debug(
303 'compress success',
304 array(
305 'size' => $size_name,
306 'image_id' => $this->id,
307 )
308 );
309 } catch ( Tiny_Exception $e ) {
310 $size->add_tiny_meta_error( $e );
311 ++$failed;
312 Tiny_Logger::error(
313 'compress failed',
314 array(
315 'error' => $e->get_message(),
316 'size' => $size_name,
317 'image_id' => $this->id,
318 )
319 );
320 }
321 $this->add_wp_metadata( $size_name, $size );
322 $this->update_tiny_post_meta();
323 }// End if().
324 }// End foreach().
325
326 /*
327 Other plugins can hook into this action to execute custom logic
328 after the image sizes have been compressed, ie. cache flushing.
329 */
330 do_action( 'tiny_image_after_compression', $this->id, $success );
331
332 return array(
333 'success' => $success,
334 'failed' => $failed,
335 );
336 }
337
338 public function delete_converted_image() {
339 $sizes = $this->get_image_sizes();
340 foreach ( $sizes as $size ) {
341 $size->delete_converted_image_size();
342 }
343 }
344
345 public function compress_retina( $size_name, $path ) {
346 if ( $this->settings->get_compressor() === null || ! $this->file_type_allowed() ) {
347 return;
348 }
349
350 if ( ! isset( $this->sizes[ $size_name ] ) ) {
351 $this->sizes[ $size_name ] = new Tiny_Image_Size( $path );
352 }
353
354 $size = $this->sizes[ $size_name ];
355
356 $compressor = $this->settings->get_compressor();
357 $convert_to = $this->convert_to();
358
359 if ( ! $size->has_been_compressed() ) {
360 $size->add_tiny_meta_start();
361 $this->update_tiny_post_meta();
362 $preserve = $this->settings->get_preserve_options( $size_name );
363
364 try {
365 $response = $compressor->compress_file( $path, false, $preserve, $convert_to );
366 $size->add_tiny_meta( $response );
367 } catch ( Tiny_Exception $e ) {
368 $size->add_tiny_meta_error( $e );
369 }
370 $this->update_tiny_post_meta();
371 }
372 }
373
374 public function remove_retina_metadata() {
375 // Remove metadata from all sizes, as this callback only fires when all
376 // retina sizes are deleted.
377 foreach ( $this->sizes as $size_name => $size ) {
378 if ( self::is_retina( $size_name ) ) {
379 unset( $this->sizes[ $size_name ] );
380 }
381 }
382 $this->update_tiny_post_meta();
383 }
384
385 public function add_wp_metadata( $size_name, $size ) {
386 if ( self::is_original( $size_name ) ) {
387 if ( isset( $size->meta['output'] ) ) {
388 $output = $size->meta['output'];
389 if ( isset( $output['width'] ) && isset( $output['height'] ) ) {
390 $this->wp_metadata['width'] = $output['width'];
391 $this->wp_metadata['height'] = $output['height'];
392 $this->wp_metadata['filesize'] = $output['size'];
393 }
394 }
395 }
396 }
397
398 public function update_tiny_post_meta() {
399 $tiny_metadata = array();
400 foreach ( $this->sizes as $size_name => $size ) {
401 $tiny_metadata[ $size_name ] = $size->meta;
402 }
403 update_post_meta( $this->id, Tiny_Config::META_KEY, $tiny_metadata );
404 /*
405 This action is being used by WPML:
406 https://gist.github.com/srdjan-jcc/5c47685cda4da471dff5757ba3ce5ab1
407 */
408 do_action( 'updated_tiny_postmeta', $this->id, Tiny_Config::META_KEY, $tiny_metadata );
409 }
410
411 public function get_image_sizes() {
412 $original = isset( $this->sizes[ self::ORIGINAL ] )
413 ? array(
414 self::ORIGINAL => $this->sizes[ self::ORIGINAL ],
415 )
416 : array();
417 $compressed = array();
418 $uncompressed = array();
419 foreach ( $this->sizes as $size_name => $size ) {
420 if ( self::is_original( $size_name ) ) {
421 continue;
422 }
423
424 if ( $size->has_been_compressed() ) {
425 $compressed[ $size_name ] = $size;
426 } else {
427 $uncompressed[ $size_name ] = $size;
428 }
429 }
430 ksort( $compressed );
431 ksort( $uncompressed );
432 return $original + $compressed + $uncompressed;
433 }
434
435 public function get_image_size( $size = self::ORIGINAL, $create = false ) {
436 if ( isset( $this->sizes[ $size ] ) ) {
437 return $this->sizes[ $size ];
438 } elseif ( $create ) {
439 return new Tiny_Image_Size();
440 } else {
441 return null;
442 }
443 }
444
445 public function filter_image_sizes( $method, $filter_sizes = null ) {
446 $selection = array();
447 if ( is_null( $filter_sizes ) ) {
448 $filter_sizes = array_keys( $this->sizes );
449 }
450 foreach ( $filter_sizes as $size_name ) {
451 if ( ! isset( $this->sizes[ $size_name ] ) ) {
452 continue;
453 }
454
455 $tiny_image_size = $this->sizes[ $size_name ];
456 if ( $tiny_image_size->$method() ) {
457 $selection[ $size_name ] = $tiny_image_size;
458 }
459 }
460 return $selection;
461 }
462
463 public function get_count( $methods, $count_sizes = null ) {
464 $stats = array_fill_keys( $methods, 0 );
465 if ( is_null( $count_sizes ) ) {
466 $count_sizes = array_keys( $this->sizes );
467 }
468 foreach ( $count_sizes as $size ) {
469 if ( ! isset( $this->sizes[ $size ] ) ) {
470 continue;
471 }
472
473 foreach ( $methods as $method ) {
474 if ( $this->sizes[ $size ]->$method() ) {
475 ++$stats[ $method ];
476 }
477 }
478 }
479 return $stats;
480 }
481
482 public function get_latest_error() {
483 $active_tinify_sizes = $this->settings->get_active_tinify_sizes();
484 $error_message = null;
485 $last_timestamp = null;
486 foreach ( $this->sizes as $size_name => $size ) {
487 if ( in_array( $size_name, $active_tinify_sizes, true ) ) {
488 if ( isset( $size->meta['error'] ) && isset( $size->meta['message'] ) ) {
489 if (
490 null === $last_timestamp ||
491 $last_timestamp < $size->meta['timestamp']
492 ) {
493 $last_timestamp = $size->meta['timestamp'];
494 $error_message = Tiny_Helpers::truncate_text(
495 $size->meta['message'],
496 140
497 );
498 }
499 }
500 }
501 }
502 return $error_message;
503 }
504
505 public function get_savings( $stats ) {
506 $before = $stats['initial_total_size'];
507 $after = $stats['compressed_total_size'];
508 if ( 0 === $before ) {
509 $savings = 0;
510 } else {
511 $savings = ( $before - $after ) / $before * 100;
512 }
513 return '' . number_format( $savings, 1 );
514 }
515
516 public function get_statistics( $active_sizes, $active_tinify_sizes ) {
517 if ( $this->statistics ) {
518 Tiny_Logger::error( 'Strangely the image statistics are asked for again.' );
519 return $this->statistics;
520 }
521
522 $this->statistics['initial_total_size'] = 0;
523 $this->statistics['compressed_total_size'] = 0;
524 $this->statistics['image_sizes_compressed'] = 0;
525 $this->statistics['available_uncompressed_sizes'] = 0;
526 $this->statistics['image_sizes_converted'] = 0;
527 $this->statistics['available_unconverted_sizes'] = 0;
528 $this->statistics['image_sizes_optimized'] = 0;
529 $this->statistics['available_unoptimized_sizes'] = 0;
530
531 $conversion_enabled = $this->settings->get_conversion_enabled();
532
533 foreach ( $this->sizes as $size_name => $size ) {
534 // skip duplicates or inactive sizes
535 if ( $size->is_duplicate() || ! isset( $active_sizes[ $size_name ] ) ) {
536 continue;
537 }
538
539 $file_size = $size->filesize();
540 $is_active_size = in_array( $size_name, $active_tinify_sizes, true );
541
542 if ( isset( $size->meta['input'] ) ) {
543 $input_size = (int) $size->meta['input']['size'];
544 $this->statistics['initial_total_size'] += $input_size;
545
546 if ( isset( $size->meta['output'] ) ) {
547 $output_size = (int) $size->meta['output']['size'];
548
549 if ( $size->modified() ) {
550 $this->statistics['compressed_total_size'] += $file_size;
551 if ( $is_active_size ) {
552 ++$this->statistics['available_uncompressed_sizes'];
553 }
554 } else {
555 $this->statistics['compressed_total_size'] += $output_size;
556 ++$this->statistics['image_sizes_compressed'];
557 }
558 } else {
559 $this->statistics['compressed_total_size'] += $input_size;
560 }
561 } elseif ( $size->exists() ) {
562 $this->statistics['initial_total_size'] += $file_size;
563 $this->statistics['compressed_total_size'] += $file_size;
564 if ( $is_active_size ) {
565 ++$this->statistics['available_uncompressed_sizes'];
566 }
567 }
568
569 if ( $is_active_size ) {
570 if ( $size->has_been_converted() ) {
571 ++$this->statistics['image_sizes_converted'];
572 } else {
573 ++$this->statistics['available_unconverted_sizes'];
574 }
575
576 $needs_compression = $size->uncompressed();
577 $needs_conversion = $conversion_enabled && $size->unconverted();
578 if ( $needs_compression || $needs_conversion ) {
579 ++$this->statistics['available_unoptimized_sizes'];
580 } elseif ( $size->compressed() && ( ! $conversion_enabled
581 || $size->has_been_converted() ) ) {
582 ++$this->statistics['image_sizes_optimized'];
583 }
584 }
585 }// End foreach().
586
587 return $this->statistics;
588 }
589
590
591 public static function is_original( $size ) {
592 return self::ORIGINAL === $size;
593 }
594
595
596 /**
597 * Check wether given $size is the original_unscaled image size.
598 *
599 * @since 3.6.14
600 *
601 * @param string $size the size descriptor
602 * @return bool true if size is the original unscaled image
603 */
604 public static function is_original_unscaled( $size ) {
605 return self::ORIGINAL_UNSCALED === $size;
606 }
607
608 public static function is_retina( $size ) {
609 return strrpos( $size, 'wr2x' ) === strlen( $size ) - strlen( 'wr2x' );
610 }
611
612 public function can_be_converted() {
613 return $this->settings->get_conversion_enabled() && $this->file_type_allowed();
614 }
615
616 /**
617 * Get the targeted conversion.
618 * If original is already converted, then we use the originals' mimetype.
619 * If nothing is converted yet, we use the settings conversion settings.
620 *
621 * @since 3.6.4
622 *
623 * @return array{string} mimetypes to which the image should be converted to
624 */
625 private function convert_to() {
626 $convert_settings = $this->settings->get_conversion_options();
627 if ( ! $convert_settings['convert'] ) {
628 // conversion is off so return no mimetypes to convert to
629 return array();
630 }
631
632 if ( isset( $this->sizes[ self::ORIGINAL ] ) ) {
633 // original is not in sizes so mimetypes are open
634 return $convert_settings['convert_to'];
635 }
636
637 $original_img_size = $this->sizes[ self::ORIGINAL ];
638 if ( $original_img_size->converted() ) {
639 // original has been convert so use that mimetype to convert to
640 return array( $original_img_size->meta['convert']['type'] );
641 }
642
643 return $convert_settings['convert_to'];
644 }
645
646 /**
647 * Marks the image as compressed without actually compressing it.
648 *
649 * This method parses existing metadata and delegates to each image size to mark
650 * itself as compressed. It considers conversion settings when marking the sizes.
651 * This is useful for images that are already optimized or when you want to skip
652 * compression while still marking them as processed in the system.
653 *
654 * @since 3.0.0
655 */
656 public function mark_as_compressed() {
657 $this->parse_tiny_metadata();
658
659 $conversion_enabled = $this->settings->get_conversion_enabled();
660
661 $active_tinify_sizes = $this->settings->get_active_tinify_sizes();
662
663 if ( $this->settings->get_conversion_enabled() ) {
664 $uncompressed_sizes = $this->filter_image_sizes( 'uncompressed', $active_tinify_sizes );
665 $unconverted_sizes = $this->filter_image_sizes( 'unconverted', $active_tinify_sizes );
666
667 $unprocessed_sizes = $uncompressed_sizes + $unconverted_sizes;
668 } else {
669 $unprocessed_sizes = $this->filter_image_sizes( 'uncompressed', $active_tinify_sizes );
670 }
671
672 foreach ( $unprocessed_sizes as $size ) {
673 $size->mark_as_compressed( $conversion_enabled );
674 }
675
676 $this->update_tiny_post_meta();
677 }
678 }
679