Created
March 28, 2025 17:39
-
-
Save mathetos/99bf01f9134a31f3829bffb6271e861a to your computer and use it in GitHub Desktop.
Disable WP Core Image compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set JPEG quality to 100 (no compression) | |
add_filter('jpeg_quality', fn($quality) => 100, 10); | |
// Prevent compression when using Imagick | |
add_filter('wp_editor_set_quality', fn($quality, $mime_type) => 100, 10, 2); | |
// Force PNGs to retain full quality (no compression via Imagick) | |
add_filter('image_editor_output_format', function($formats) { | |
$formats['image/png'] = 'png'; // Ensure PNGs aren't converted to JPEG or compressed | |
return $formats; | |
}); | |
// Optional: prefer Imagick if available (better for quality control than GD) | |
add_filter('wp_image_editors', function($editors) { | |
return ['WP_Image_Editor_Imagick', 'WP_Image_Editor_GD']; | |
}); | |
// Set default image size to 'full' when inserting into the block editor | |
add_filter('image_default_size', function() { | |
return 'full'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment