Optimizing Images for WordPress Deployments with DeployBot Gists

Images are a critical component of any WordPress site. They can enhance the user experience, but they can also slow down your site if not optimized properly. Using DeployBot, you can easily integrate image optimization into your deployment process. The following tutorial will guide you through setting up an image optimization step in your DeployBot workflow using a provided bash script.

If you’ve read this far, you’re probably a DeployBot user and familiar with version control systems, CI/CD, and other related topics. If not, we’ve compiled several beginner’s guides: Laravel, Digital Ocean, Ruby on Rails, Docker, Craft CMS, Ghost CMS, Google Web Starter Kit, Grunt or Gulp, Slack, Python, Heroku and many more.

Learn how to get started with DeployHQ here.

Prerequisites

  • A DeployBot account set up with a connected repository and environment.
  • Basic knowledge of SSH and shell scripting.
  • Access to the server where WordPress is hosted with permissions to install software.

Step 1: Understanding the Script

The script included in DeployBot Gists installs image compression tools (jpegoptim and optipng) on a server running Ubuntu 20.04 and compresses JPG and PNG images in a specified directory. The script uses the --max=85 option for jpegoptim to set the maximum quality to 85 (out of 100), and -o7 for optipng to optimize at level 7.

Step 2: Integrating the Script with DeployBot

  1. Create a Custom Script in DeployBot:
    • Log in to your DeployBot account.
    • Go to your environment settings by clicking on the environment name on the dashboard.
    • Under the "Deployments" tab, find the "Run shell commands" section.
    • Click "Add shell command" to create a new custom script.
  2. Copy and Customize the Script:
    • Copy the provided bash script into the command editor in DeployBot.
    • Replace $HOME/images with the actual directory where your WordPress images are stored, for example, $HOME/public_html/wp-content/uploads.
  3. Add the Script to Pre-Deployment or Post-Deployment Steps:
    • Choose when the script should run:
      • Pre-deployment: Optimize images before the code is deployed.
      • Post-deployment: Optimize images after the deployment is complete.
    • Paste the script into the appropriate section in DeployBot.

Step 3: Running the Deployment

  1. Initiate a Deployment:
    • Go back to your DeployBot dashboard.
    • Select the repository and environment where you want to deploy your code.
    • Click "Deploy" to start the process. Your custom script will run during the deployment as per the pre-deployment or post-deployment settings you've configured.
  2. Monitor the Deployment Process:
    • Watch the deployment log to ensure the image compression is executed without errors.
    • The script will output the status of each image it compresses or skips.
  3. Verify Image Optimization:
    • Once the deployment and image compression have finished, you can verify the optimized images on your server.
    • Check the file sizes of the images before and after optimization to measure the effectiveness.

Step 4: Best Practices

  • Backup Images: Always keep backups of your original images before applying any compression, in case you need to revert or adjust compression settings.
  • Regular Maintenance: Set up a regular schedule for image optimization as part of your deployment process to ensure that new images are consistently optimized.
  • Quality Control: Test different compression levels to find the balance between image quality and file size that works best for your WordPress site.

Conclusion

Integrating image optimization into your DeployBot deployment workflow can significantly improve the loading times and performance of your WordPress site. By automating this process, you can ensure that all images are consistently optimized, which will benefit both your site's user experience and search engine ranking. With the bash script from DeployBot Gists, this optimization step becomes a straightforward part of your deployment routine.