Envira Gallery Documentation

Documentation, Reference Materials and Tutorials for Envira Gallery

Change Image Crop Position

Have you ever wanted to change the default crop position for your gallery images? By default the crop position for all cropped images in Envira is centered. This tutorial will help you create a plugin that can change the default crop position for you.

This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. We’ll need to create and upload a basic WordPress plugin.

Creating the Plugin

To change the crop position for your Envira gallery/album images, just add the following code to a new file at wp-content/plugins/envira-change-crop-position.php.

The below code uses the position 'tl'. This means all images will be cropped Top Left. Here is a complete list for each crop position, simply choose the position you want for your site and be sure to use that in the $args['position'] = 'tl'; before saving or activating the plugin.

  • c = This option will crop your images Center / Center (currently default).
  • tr = This option will crop your images Top / Right.
  • tl = This option will crop your images Top / Left.
  • br = This option will crop your images Bottom / Right.
  • bl = This option will crop your images Bottom / Left.
<?php
/*
* Plugin Name: Envira Gallery - Change Crop Position
* Plugin URI: https://enviragallery.com
* Version: 1.0.0
* Author: Envira Gallery Team
* Author URI: https://enviragallery.com
* Description: This plugin will change the default crop position when cropping your images
*/

add_filter( 'envira_gallery_crop_image_args', 'tgm_envira_crop_image_position' );
function tgm_envira_crop_image_position( $args ) {
    
    $args['position'] = 'tl';
    return $args;
    
}

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 below that matches the page builder you’re using into the file and save the file as envira-change-crop-position.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 Envira Gallery – Change Crop Position plugin.

Activate the Envira Change Crop Position Plugin

Would you like to customize some other Envira options? Check out our tutorial on How to Style Image Title and Caption Hover Effects.

FAQs

Q: Why haven’t my existing gallery images changed?

A: When you activated the plugin to change your crop position, that will only affect the images going forward. To adjust the gallery images you already have, you can install a plugin called Regenerate Thumbnails. This plugin will take any gallery images that have been cropped already and regenerate them based on your new settings.

Activate the Regenerate Thumbnails Plugin

Once the plugin is installed and activated, just go to Tools » Regenerate Thumbnails and run the process to re-create your cropped images based on your new settings.

Run the Regenerate Thumbnails plugin to regenerate your gallery images


[i]
[i]
[i]
[i]