[wp-trac] [WordPress Trac] #35725: Add mime-type for Webp
WordPress Trac
noreply at wordpress.org
Sat Dec 16 21:15:33 UTC 2017
#35725: Add mime-type for Webp
-------------------------------------------------+-------------------------
Reporter: markoheijnen | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
Component: Media | Review
Severity: normal | Version: 3.5
Keywords: has-patch 2nd-opinion needs-testing | Resolution:
has-unit-tests | Focuses:
-------------------------------------------------+-------------------------
Changes (by blobfolio):
* keywords: has-patch => has-patch 2nd-opinion needs-testing has-unit-
tests
Comment:
The `35725.diff` patch adds full WebP support to WordPress:
* Whitelists `webp` files for upload;
* Adds `webp` to the list of image formats for admin display, thumbnail
generation, etc.;
* Provides numerous workarounds for environments where WebP support
exists in a partial state;
* Supports `VP8`, `VP8L`, and `VP8X` container formats;
* GD handling (`PHP5.6+` for `VP8`, `PHP7.0+` for the rest);
* ImageMagick handling (works as long as the system's binary was compiled
with WebP support);
[[BR]]
This patch introduces one new function:
{{{#!php
/**
* Wrapper for getimagesize()
*
* The native PHP function might not support newer formats.
*
* @since 5.0
*
* @see {https://core.trac.wordpress.org/ticket/35725}
*
* @param string $file Full path to the file.
* @param array $info Additional metadata to pull.
* @return array|false An array containing width, height, type constant,
attributes, and media type.
*/
function wp_get_image_size( $file, &$info = array() ) { ... }
}}}
All calls to the native `getimagesize()` function have been redirected to
this wrapper to ensure that WebP dimensions are properly reported. This
also fixes the inconsistent use of error suppression that existed
previously.
This wrapper can later be expanded to account for other new formats, such
as #42775.
[[BR]]
A few other things to note:
* Hosts that do not support WebP through GD or ImageMagick will still
allow files to be uploaded, they just won't get intermediate sizes.
* There was once a bug in GD that confused `ARGB` with `RGBA`, causing
colors to shift. This has been fixed upstream, but some unsupported
distributions (like Debian Squeeze) might still be using it.
* ImageMagick on Arch Linux is currently causing a segfault when dumping
a WebP via the `getImageBlob()` method. As a workaround, stream previews
(when e.g. editing an image) output `png` instead. This doesn't affect the
saved results, so seems safe to keep.
[[BR]]
One final note:
WebP browser support (https://caniuse.com/#search=webp) is not universal.
This patch restricts its focus to backend handling, but there is
opportunity for a future frontend-focused patch to provide `jpg`/`png`
fallbacks. The use of the HTML5 `<picture>` element seems like the best
approach for such work. As it happens, @desrosj is currently working on
general `<picture>` support for WP, so if/when that lands, a frontend WebP
enhancement should be easy. :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35725#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list