Skip to content

Instantly share code, notes, and snippets.

View adamsilverstein's full-sized avatar
💭
Working remotely, as usual

Adam Silverstein adamsilverstein

💭
Working remotely, as usual
View GitHub Profile
@adamsilverstein
adamsilverstein / set-82.php
Created August 29, 2022 15:45
Set all quality to 82
<?php
/**
* Use the `wp_editor_set_quality` filter for testing.
*/
function set_webp_quality() {
return 82;
}
@adamsilverstein
adamsilverstein / low-webp-quality.php
Last active August 25, 2022 19:07
Test setting WebP quality
<?php
/**
* Use the `wp_editor_set_quality` filter for testing.
*/
function set_webp_quality( $quality, $mime_type ) {
error_log( sprintf( 'wp_editor_set_quality mime type: %s', $mime_type ) );
if ( 'image/webp' === $mime_type ) {
return 1;
}
@adamsilverstein
adamsilverstein / median_image_bytes_webp.sql
Last active August 22, 2022 18:35
Calculate the median image size for WordPress pages using/not using WebP images. Change mobile to desktop for desktop sizes.
SELECT
has_webp,
APPROX_QUANTILES(bytesImg, 1000)[OFFSET(500)] / 1024 / 1024 AS median_img_mbytes
FROM (
SELECT DISTINCT
url,
info AS version
FROM
`httparchive.technologies.2022_07_01_mobile`
WHERE
@adamsilverstein
adamsilverstein / wp-webp.sql
Created August 18, 2022 18:13
WebP by WordPress version Query
SELECT
mobile.version,
ROUND(pct_webp_mobile, 3) AS pct_webp_mobile,
ROUND(pct_webp_desktop, 3) AS pct_webp_desktop
FROM
(
SELECT
version, pct_webp AS pct_webp_mobile
FROM
(
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php
index 6b63d7e9fd..e17b787223 100644
--- a/src/wp-includes/class-wp-image-editor.php
+++ b/src/wp-includes/class-wp-image-editor.php
@@ -414,12 +414,10 @@ abstract class WP_Image_Editor {
$filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
}
- if ( $mime_type && ( $mime_type !== $this->mime_type ) ) {
- // The image will be converted when saving. Set the quality for the new mime-type if not already set.
( function( d, i, s, p ) {
s = d.createElement( s );
s.src = '{$fallback_url}';
i = d.createElement( i );
i.src = p + 'jIAAABXRUJQVlA4ICYAAACyAgCdASoCAAEALmk0mk0iIiIiIgBoSygABc6zbAAA/v56QAAAAA==';
i.onload = function() {
i.src = p + 'h4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
};
i.onerror = function() {
d.body.appendChild( s );
SELECT
mobile.version,
ROUND(pct_webp_mobile, 3) AS pct_webp_mobile,
ROUND(pct_webp_desktop, 3) AS pct_webp_desktop
FROM
(
SELECT
version, pct_webp AS pct_webp_mobile
FROM
(
➜ ll
total 45600
166K 2 14:14 sample0-1024x576.jpg
118K 2 14:14 sample0-1024x576.webp
168K 2 14:14 sample0-1038x576.jpg
120K 2 14:15 sample0-1038x576.webp
28K 2 14:14 sample0-150x150.jpg
7.0K 2 14:14 sample0-150x150.webp
304K 2 14:14 sample0-1536x864.jpg
220K 2 14:15 sample0-1536x864.webp
166K sample0-1024x576.jpg
118K sample0-1024x576.webp
168K sample0-1038x576.jpg
120K sample0-1038x576.webp
28K sample0-150x150.jpg
7.0K sample0-150x150.webp
304K sample0-1536x864.jpg
220K sample0-1536x864.webp
468K sample0-2048x1152.jpg
WITH picture AS (
SELECT
url
FROM
`httparchive.pages.2022_01_01_mobile`
WHERE
JSON_VALUE(JSON_VALUE(payload, '$._element_count'), '$.picture') IS NOT NULL
), wordpress AS (
SELECT DISTINCT
url