PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / classes / image / image-conversion.php

image-conversion.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at classes/image/image-conversion.php

54 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Classes\Image;
4
5 use ImageOptimization\Modules\Settings\Classes\Settings;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Image_Conversion {
12 protected ?string $convert_to_format;
13 protected array $options;
14
15 public function is_enabled(): bool {
16 return Image_Conversion_Option::ORIGINAL !== $this->convert_to_format;
17 }
18
19 public function get_current_conversion_option(): string {
20 return $this->convert_to_format;
21 }
22
23 public function get_current_file_extension(): ?string {
24 if ( ! $this->is_enabled() ) {
25 return null;
26 }
27
28 return $this->options[ $this->convert_to_format ]['extension'];
29 }
30
31 public function get_current_mime_type(): ?string {
32 if ( ! $this->is_enabled() ) {
33 return null;
34 }
35
36 return $this->options[ $this->convert_to_format ]['mime_type'];
37 }
38
39 public function __construct() {
40 $this->convert_to_format = Settings::get( Settings::CONVERT_TO_FORMAT_OPTION_NAME );
41
42 $this->options = [
43 Image_Conversion_Option::WEBP => [
44 'extension' => 'webp',
45 'mime_type' => 'image/webp',
46 ],
47 Image_Conversion_Option::AVIF => [
48 'extension' => 'avif',
49 'mime_type' => 'image/avif',
50 ],
51 ];
52 }
53 }
54