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 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-avif-upload.php
admin-site-enhancements / classes Last commit date
class-activation.php 7 months ago class-admin-menu-organizer.php 7 months ago class-admin-menu-svg-icon-mask.php 7 months ago class-auto-publish-posts-with-missed-schedule.php 7 months ago class-avif-upload.php 7 months ago class-captcha-protection.php 7 months ago class-change-login-url.php 7 months ago class-cleanup-admin-bar.php 7 months ago class-common-methods.php 7 months ago class-content-duplication.php 7 months ago class-content-order.php 7 months ago class-custom-admin-footer-text.php 7 months ago class-custom-body-class.php 7 months ago class-custom-css.php 7 months ago class-custom-nav-menu-items-in-new-tab.php 7 months ago class-deactivation.php 7 months ago class-disable-author-archives.php 7 months ago class-disable-comments.php 7 months ago class-disable-dashboard-widgets.php 7 months ago class-disable-embeds.php 7 months ago class-disable-feeds.php 7 months ago class-disable-gutenberg.php 7 months ago class-disable-rest-api.php 7 months ago class-disable-smaller-components.php 7 months ago class-disable-updates.php 7 months ago class-disable-xml-rpc.php 7 months ago class-display-system-summary.php 7 months ago class-email-address-obfuscator.php 7 months ago class-email-delivery.php 7 months ago class-enhance-list-tables.php 7 months ago class-external-permalinks.php 7 months ago class-heartbeat-control.php 7 months ago class-hide-admin-bar.php 7 months ago class-hide-admin-notices.php 7 months ago class-image-sizes-panel.php 7 months ago class-image-upload-control.php 7 months ago class-insert-head-body-footer-code.php 7 months ago class-last-login-column.php 7 months ago class-limit-login-attempts.php 7 months ago class-login-id-type.php 7 months ago class-login-logout-menu.php 7 months ago class-maintenance-mode.php 7 months ago class-manage-ads-appads-txt.php 7 months ago class-manage-robots-txt.php 7 months ago class-media-replacement.php 7 months ago class-multiple-user-roles.php 7 months ago class-obfuscate-author-slugs.php 7 months ago class-open-external-links-in-new-tab.php 7 months ago class-password-protection.php 7 months ago class-redirect-after-login.php 7 months ago class-redirect-after-logout.php 7 months ago class-redirect-fourofour.php 7 months ago class-registration-date-column.php 7 months ago class-revisions-control.php 7 months ago class-search-engines-visibility.php 7 months ago class-settings-fields-render.php 7 months ago class-settings-sanitization.php 7 months ago class-settings-sections-fields.php 7 months ago class-show-custom-taxonomy-filters.php 7 months ago class-site-identity-on-login-page.php 7 months ago class-svg-upload.php 7 months ago class-various-admin-ui-enhancements.php 7 months ago class-view-admin-as-role.php 7 months ago class-wider-admin-menu.php 7 months ago class-wp-config-transformer.php 7 months ago
class-avif-upload.php
236 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class for AVIF Upload module
7 *
8 * @since 6.9.5
9 */
10 class AVIF_Upload {
11
12 /**
13 * Add AVIF mime type to list of mime types
14 *
15 * @since 5.7.0
16 */
17 public function add_avif_mime_type( $wp_get_mime_types ) {
18
19 $wp_get_mime_types['avif'] = 'image/avif';
20 return $wp_get_mime_types;
21
22 }
23
24 /**
25 * Add AVIF mime type to allowed mime types
26 *
27 * @since 5.7.0
28 */
29 public function allow_avif_mime_type_upload( $mimes ) {
30
31 $mimes['avif'] = 'image/avif';
32 return $mimes;
33
34 }
35
36 /**
37 * Add AVIF to mapping of mime types to their respective extensions
38 *
39 * @since 5.7.0
40 */
41 public function add_avif_mime_type_to_exts( $mime_to_ext ) {
42
43 $mime_to_ext['image/avif'] = 'avif';
44 return $mime_to_ext;
45
46 }
47
48 /**
49 * Add correct dimension for AVIF images
50 *
51 * @link https://plugins.trac.wordpress.org/browser/avif-support/trunk/includes/AvifSupport.php#L104
52 * @since 5.7.0
53 */
54 public function add_avif_image_dimension( $metadata, $attachment_id, $context ) {
55
56 if ( empty( $metadata ) ) {
57 return $metadata;
58 }
59
60 $attachment_post = get_post( $attachment_id );
61
62 if ( ! $attachment_post || is_wp_error( $attachment_post ) ) {
63 return $metadata;
64 }
65
66 if ( 'image/avif' !== $attachment_post->post_mime_type ) {
67 return $metadata;
68 }
69
70 // Fix width and height
71
72 if (
73 ( ! empty( $metadata['width'] )
74 && ( 0 !== $metadata['width'] ) )
75 && ( ! empty( $metadata['height'] )
76 && 0 !== $metadata['height'] )
77 ) {
78 return $metadata;
79 }
80
81 $file = get_attached_file( $attachment_id );
82
83 if ( ! $file ) {
84 return $metadata;
85 }
86
87 if ( empty( $metadata['width'] ) ) {
88 $metadata['width'] = 0;
89 }
90
91 if ( empty( $metadata['height'] ) ) {
92 $metadata['height'] = 0;
93 }
94
95 if ( empty( $metadata['file'] ) ) {
96 $metadata['file'] = _wp_relative_upload_path( $file );
97 }
98
99 if ( empty( $metadata['sizes'] ) ) {
100 $metadata['sizes'] = array();
101 }
102
103 $img_size = wp_getimagesize( $file );
104
105 // Legacy PHP Version, return false, fake it till manual.
106 if ( empty( $img_size ) ) {
107 $img_size = array(
108 0 => 0,
109 1 => 0,
110 2 => 19,
111 3 => 'width="0" height="0"',
112 'mime' => 'image/avif',
113 );
114 }
115
116 if ( is_array( $img_size ) && ( 0 !== $img_size[0] ) && ( 0 !== $img_size[1] ) ) {
117 // Do nothing, we have what we need
118 } else {
119
120 // Manually get width and height
121 $binary_string = file_get_contents( $file );
122 $ispe_pos = strpos( $binary_string, 'ispe' );
123
124 if ( false === $ispe_pos ) {
125 // Corrupted Image.
126 return false;
127 }
128
129 $dim_start_pos = $ispe_pos + 8;
130 $dim_bin = substr( $binary_string, $dim_start_pos, 8 );
131 $width = hexdec( bin2hex( substr( $dim_bin, 0, 4 ) ) );
132 $height = hexdec( bin2hex( substr( $dim_bin, 4, 8 ) ) );
133
134 if ( $width && $height && is_numeric( $width ) && is_numeric( $height ) ) {
135 $img_size[0] = absint( $width );
136 $img_size[1] = absint( $height );
137 }
138
139 // wp_getimagesize() failed, try with Imagick
140 // if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
141 // try {
142 // $imagick = new \Imagick( $file );
143 // $img_dim = $imagick->getImageGeometry();
144 // $img_size[0] = $img_dim['width'];
145 // $img_size[1] = $img_dim['height'];
146
147 // $imagick->clear();
148 // } catch ( \Exception $e ) {
149 // // Do nothing for now.
150 // }
151 // }
152
153 }
154
155 if ( ! $img_size ) {
156 $avif_specs = false;
157 } else {
158 $file_size = filesize( $file );
159 $avif_specs = array(
160 'width' => $img_size[0],
161 'height' => $img_size[1],
162 'mime' => $img_size['mime'],
163 'dimension' => $img_size[0] . 'x' . $img_size[1],
164 'ext' => str_replace( 'image/', '', $img_size['mime'] ),
165 'size' => $file_size,
166 'size_format' => size_format( $file_size ),
167 );
168 }
169
170 if ( is_wp_error( $avif_specs ) || ! $avif_specs ) {
171 return $metadata;
172 }
173
174 $metadata['width'] = $avif_specs['width'];
175 $metadata['height'] = $avif_specs['height'];
176
177 return $metadata;
178
179 // Fix scaled version of the image
180
181 }
182
183 /**
184 * Make sure AVIF files are displayable in the browser
185 *
186 * @since 5.7.0
187 */
188 public function make_avif_displayable( $result, $path ) {
189 if ( str_ends_with( $path, '.avif' ) ) {
190 return true;
191 }
192
193 return $result;
194 }
195
196 /**
197 * Handle rare scenarios where exif and fileinfo fail to detect AVIF
198 *
199 * @since 5.7.0
200 */
201 public function handle_exif_and_fileinfo_fail( $wp_check_filetype_and_ext, $file, $filename, $mimes, $real_mime ) {
202
203 // AVIF is properly handled, no need to do anything else
204 if ( $wp_check_filetype_and_ext['ext'] && $wp_check_filetype_and_ext['type'] ) {
205 return $wp_check_filetype_and_ext;
206 }
207
208 // Not an .avif file, no need to do anything else
209 if ( ! str_ends_with( $filename, '.avif' ) ) {
210 return $wp_check_filetype_and_ext;
211 } else {
212 $binary_string = file_get_contents( $file );
213 $ispe_pos = strpos( $binary_string, 'ispe' );
214
215 if ( false === $ispe_pos ) {
216 // Corrupted Image.
217 return false;
218 }
219
220 $dim_start_pos = $ispe_pos + 8;
221 $dim_bin = substr( $binary_string, $dim_start_pos, 8 );
222 $width = hexdec( bin2hex( substr( $dim_bin, 0, 4 ) ) );
223 $height = hexdec( bin2hex( substr( $dim_bin, 4, 8 ) ) );
224
225 // If this is a valid image with proper width and height, set filetype and ext to AVIF
226 if ( $width && $height && is_numeric( $width ) && is_numeric( $height ) ) {
227 $wp_check_filetype_and_ext['type'] = 'image/avif';
228 $wp_check_filetype_and_ext['ext'] = 'avif';
229 }
230
231 return $wp_check_filetype_and_ext;
232 }
233
234 }
235
236 }