Skip to content

Instantly share code, notes, and snippets.

@mathetos
Created March 28, 2025 17:39
Show Gist options
  • Save mathetos/99bf01f9134a31f3829bffb6271e861a to your computer and use it in GitHub Desktop.
Save mathetos/99bf01f9134a31f3829bffb6271e861a to your computer and use it in GitHub Desktop.
Disable WP Core Image compression
<?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