Soliloquy Documentation

Documentation, Reference Materials, and Tutorials for Soliloquy

Adjust Image Quality

Would you like to remove the default image compression that WordPress applies to your uploaded images? WordPress automatically applies image compression to each image uploaded to your site. This tutorial will walk you through how to turn off image compression with the use of a plugin we will create.

Note: This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. In order to adjust the default image quality, we’ll need to create and upload a basic WordPress plugin.


Creating the Plugin

To create this custom query filter, just add the following code to a new file at wp-content/plugins/soliloquy-image-quality.php.

[php]<?php
/**
* Plugin Name: Soliloquy – Image Quality
* Plugin URI: https://soliloquywp.com
* Version: 1.0
* Author: Soliloquy Team
* Author URI: https://soliloquywp.com
* Description: Override the default image quality when resizing and cropping images
*/
/**
* Override the default image quality when resizing and cropping images
*
* @param array $args Arguments
* @return array Arguments
*/
function sol_soliloquy_image_quality( $args ) {

// Either set the value explicitly, or call your custom function which returns the quality value
$args[‘quality’] = 80;
//$args[‘quality’] = custom_image_quality($args[‘quality’])

return $args;

}
add_filter( ‘soliloquy_crop_image_args’, ‘sol_soliloquy_image_quality’ );[/php]

If you’re unsure how to create a plugin file, follow these steps below:

  1. Open a text file and make sure that it is a plain text document. You can use a plain text editor like Notepad or a code editor of your choice.
  2. Next, copy and paste the code shown above into the file and save the file as soliloquy-image-quality.php
  3. Once you’ve saved the file you can easily upload this directly to your /plugins directory on your server using FTP or you can right-click on the text document and zip (or compress).
  4. Finally, log in to your WordPress dashboard and go to Plugins » Add New » Upload Plugin and upload the .zip file you just created in the previous step.

Activate the Plugin

Your next step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Soliloquy – Image Quality plugin.

Activate the image quality plugin

You can adjust the image quality by changing the $args['quality'] = 80; from 80% to 60% which would look like this.

$args['quality'] = 60;

Would you like to like to learn about some other site optimizations? Take a look at our documentation on How to Optimize Your Website and Images for Speed.