How to Stop WordPress automatically compressing the images?

For some portfolio website, you may not want WordPress automatically compresses all the images you upload.

Here is the step by step:

  1. Add to functions.php
add_filter('jpeg_quality', function($arg){return 100;});   
add_filter('wp_editor_set_quality', function($arg){return 100;});
  1. Regenerate thumbnails.

Here is the plugin.

If you use WP-CLI

$ wp media regenerate

Note: You should however edit the images to the appropriate size. If your website has a limit of 800px width, don’t upload a 2000px wide image.