Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

WordPress Grayscale Image Tutorial

Any website should have images, which may significantly improve your WordPress site’s aesthetic appeal.

To get a more muted impression, you can want to sometimes reduce the color intensity of your photographs. Wordpress grayscale graphics are one method of doing this. Exactly how to achieve it is what we’ll demonstrate in this piece.

What is Grayscale?

Grayscale, commonly referred to as black-and-white, is a color scheme that strips a picture of all color and presents it in various tones of gray. This may have a dramatic effect and enhance the creative or professional quality of a photograph.
 

Grayscale Images in WordPress

There are two ways to grayscale a picture in WordPress: a plugin or Custom Code. This is how you do it:

Option 1: Use a Plugin

Utilizing a plugin is the simplest approach to grayscale photos in WordPress. There are a number of plugins that can accomplish this, however we suggest the “WP Image Effects” plugin.

Here are the steps to follow:

  1. Install and activate the “WP Image Effects” plugin.
  2. Go to Media > Library in your WordPress dashboard and select the image you want to grayscale.
  3. Click on the “Edit Image” button.
  4. Click on the “Effects” tab.
  5. Check the box next to “Grayscale.”
  6. Click on the “Save” button.

That’s it! Your image is now grayscale.

Option 2: Use Custom Code

If you prefer not to use a plugin, you can grayscale images in WordPress using custom code. Here’s how:

  1. Open your theme’s functions.php file.
  2. Add the following code:
function grayscale_image($attachment_ID) {
    $image_url = wp_get_attachment_image_src($attachment_ID, 'full');
    $image_path = parse_url($image_url[0], PHP_URL_PATH);
    $image_abs_path = $_SERVER['DOCUMENT_ROOT'] . $image_path;
    if (!copy($image_abs_path, $image_abs_path . '.bak')) {
        return new WP_Error('error', 'Failed to backup image.');
    }
    $image = imagecreatefromjpeg($image_abs_path);
    if (!$image) {
        return new WP_Error('error', 'Failed to create image.');
    }
    imagefilter($image, IMG_FILTER_GRAYSCALE);
    if (!imagejpeg($image, $image_abs_path)) {
        return new WP_Error('error', 'Failed to save image.');
    }
    imagedestroy($image);
    return true;
}

add_action('add_attachment', 'grayscale_image');
  1. Save the file.

That’s it! Now, whenever you upload an image, it will be automatically grayscale.

Conclusion

To get a more muted impact and give your website a more polished appearance, grayscaling photos in WordPress might be a terrific option. You don’t need to have a high level of technical expertise to get this effect with the aforementioned alternatives. If you want to create WordPress Website / WordPress Services / Support you can check our services.

The post WordPress Grayscale Image Tutorial appeared first on itcroc.



This post first appeared on My Company, please read the originial post: here

Share the post

WordPress Grayscale Image Tutorial

×

Subscribe to My Company

Get updates delivered right to your inbox!

Thank you for your subscription

×