PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / league / glide / src / Manipulators / Encode.php

Encode.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/league/glide/src/Manipulators/Encode.php

93 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace League\Glide\Manipulators;
4
5 use Intervention\Image\Image;
6
7 /**
8 * @property string $fm
9 * @property string $q
10 */
11 class Encode extends BaseManipulator
12 {
13 /**
14 * Perform output image manipulation.
15 *
16 * @param Image $image The source image.
17 *
18 * @return Image The manipulated image.
19 */
20 public function run(Image $image)
21 {
22 $format = $this->getFormat($image);
23 $quality = $this->getQuality();
24
25 if (in_array($format, ['jpg', 'pjpg'], true)) {
26 $image = $image->getDriver()
27 ->newImage($image->width(), $image->height(), '#fff')
28 ->insert($image, 'top-left', 0, 0);
29 }
30
31 if ('pjpg' === $format) {
32 $image->interlace();
33 $format = 'jpg';
34 }
35
36 return $image->encode($format, $quality);
37 }
38
39 /**
40 * Resolve format.
41 *
42 * @param Image $image The source image.
43 *
44 * @return string The resolved format.
45 */
46 public function getFormat(Image $image)
47 {
48 if (array_key_exists($this->fm, static::supportedFormats())) {
49 return $this->fm;
50 }
51
52 return array_search($image->mime(), static::supportedFormats(), true) ?: 'jpg';
53 }
54
55 /**
56 * Get a list of supported image formats and MIME types.
57 *
58 * @return array<string,string>
59 */
60 public static function supportedFormats()
61 {
62 return [
63 'avif' => 'image/avif',
64 'gif' => 'image/gif',
65 'jpg' => 'image/jpeg',
66 'pjpg' => 'image/jpeg',
67 'png' => 'image/png',
68 'webp' => 'image/webp',
69 'tiff' => 'image/tiff',
70 ];
71 }
72
73 /**
74 * Resolve quality.
75 *
76 * @return int The resolved quality.
77 */
78 public function getQuality()
79 {
80 $default = 90;
81
82 if (!is_numeric($this->q)) {
83 return $default;
84 }
85
86 if ($this->q < 0 or $this->q > 100) {
87 return $default;
88 }
89
90 return (int) $this->q;
91 }
92 }
93