How to add watermarks to your images easily and for free in WordPress

There are many types of websites for which it is essential to apply watermarks to your images, from artists’ portfolios to real estate websites.

Watermarks are important for several reasons:

  • Protection against theft.
  • Signature.
  • Brand diffusion.
  • Authorship recognition.

So let’s learn how to add watermarks to images in WordPress, and I won’t roll up on premium plugins, let’s see how it’s done easily and for free.

How to add watermarks with a plugin

Come on, install the Easy Watermark plugin, there are others but after trying them all this is the one that works best and has more useful features and free.

You install it like any other plugin, from the plugin installer of your WordPress.

Once installed and active, go to its settings page in Tools > Easy Watermark because there are a few things to configure.

First assign the user permissions, in case you want the author or editor profiles to be able to:

  • Create watermarks
  • Edit other people’s watermarks
  • Apply watermarks

Watermark settings

My advice is to leave it as it is, without activating it, unless some user with that profile needs it to do this.

Then go through the general settings. There you can…

  • Set the quality of the JPG generated when the watermark is applied.
  • Filter the srcset attribute: So that all sizes are displayed with a watermark (recommended)
  • Activate backups: To save copies of your originals, in case you decide to restore them without watermarks (strongly recommended)

In the next tools tab is where you will start to see the potential of the plugin, because from there you can launch the bulk watermark addition tool and the restore tool.

Image watermarks

But first you have to create the watermarks, and you can create a maximum of 2 watermarks:

  • An image watermark
  • A text watermark

And you can apply one or both to your images, either one by one or in batches, massively.

To do this, go to the first tab of the settings, the watermarks tab, and add the first one.

Then choose whether it will be image or text.

If it is a picture, the main settings are as follows…

As you see in the image it’s very easy to configure, you can even choose a preview image to see how the watermark will look in your images, something really useful, that I haven’t seen in any other plugin, neither free nor paid.

A bit further down you can scale the size of the watermark image, in case you want to make it smaller or bigger (not recommended, it will look pixelated).

The next step is to decide which image sizes to add watermarks to.

And, following the editing page of your watermark, almost the most important thing: which images will be automatically applied when you upload them.

Text watermarks

If you prefer to make a text watermark the process is very similar to the above.

As you will see in the previous capture, instead of image settings, they will be text settings. All other settings are the same except for the placeholders.

You can use them instead of typing a text, to automatically add the name of the author of a publication, and much more.

When you’re done, you have your watermarks to apply.

Bulk Adding Watermarks

If you want to get off to a good start, it’s a good idea to apply the process of bulk adding watermarks, on the tools tab, but you can also do this from the media screen in the WordPress Media Library.

Just put the media in the list mode display, select the ones you want to add a watermark to, and in the “Bulk Actions” dropdown choose the watermark, and then next to it, which watermark you have created to apply to the selected images.

When you click the apply button the process is done automatically.

How to restore original images, without watermarks, in batch

Similarly, if you need to, you can also restore the original images, on the same screen and almost the same, simply by selecting the restore option.

How to add watermarks with code

The good old Alex Mills, sadly deceased, left us this code, which you can install directly as a plugin – without adjustments – to easily add watermarks automatically to all uploaded images.

<?php
/*
 * Plugin Name: WordPress.com Watermark Image Uploads
 * Author:      Alex Mills
 * Author URI:  http://automattic.com/
 */
 
class WPcom_Watermark_Uploads {
 
 public $watermark;
 
 // Class initialization
 function __construct() {
 
 $this->watermark = apply_filters( 'wpcom_watermark_image', STYLESHEETPATH . '/images/upload-watermark.png' ); //ruta de tu imagen de marca de agua
 if ( ! file_exists( $this->watermark ) )
 return false;
 
 add_filter( 'wp_handle_upload_prefilter', array( &$this, 'handle_file' ), 100 );
 add_filter( 'wp_upload_bits_data',        array( &$this, 'handle_bits' ), 10, 2 ); // http://core.trac.wordpress.org/ticket/12493
 }
 
 // For filters that pass a $_FILES array
 public function handle_file( $file ) {
 
 // Make sure the upload is valid
 if ( 0 == $file['error'] && is_uploaded_file( $file['tmp_name'] ) ) {
 
 // Check file extension (can't use $file['type'] due to Flash uploader sending application/octet-stream)
 if ( ! $type = $this->get_type( $file['name'] ) ) {
 return $file;
 }
 
 // Load the image into $image
 switch ( $type ) {
 case 'jpeg':
 if ( ! $image = @imagecreatefromjpeg( $file['tmp_name'] ) ) {
 return $file;
 }
 
 // Get the JPEG quality setting of the original image
 if ( $imagecontent = @file_get_contents( $file['tmp_name'] ) )
 $quality = $this->get_jpeg_quality_wrapper( $imagecontent );
 if ( empty( $quality ) )
 $quality = 90;
 
 break;
 
 case 'png':
 if ( !$image = @imagecreatefrompng( $file['tmp_name'] ) ) {
 return $file;
 }
 break;
 
 default;
 return $file;
 }
 
 // Run the $image through the watermarker
 $image = $this->watermark( $image );
 
 // Save the new watermarked image
 switch ( $type ) {
 case 'jpeg':
 imagejpeg( $image, $file['tmp_name'], $quality );
 case 'png':
 imagepng( $image, $file['tmp_name'] );
 }
 
 imagedestroy( $image );
 }
 
 return $file;
 }
 
 // For filters that pass the image as a string
 public function handle_bits( $bits, $file ) {
 
 // Check file extension
 if ( ! $type = $this->get_type( $file ) ) {
 return $bits;
 }
 
 // Convert the $bits into an $image
 if ( ! $image = imagecreatefromstring( $bits ) ) {
 return $bits;
 }
 
 // Run the $image through the watermarker
 $image = $this->watermark( $image );
 
 // Get the $image back into a string
 ob_start();
 switch ( $type ) {
 case 'jpeg':
 // Get the JPEG quality setting of the original image
 $quality = $this->get_jpeg_quality_wrapper( $bits );
 if ( empty($quality) )
 $quality = 100;
 
 if ( ! imagejpeg( $image, null, $quality ) ) {
 ob_end_clean();
 return $bits;
 }
 break;
 case 'png':
 if ( ! imagepng( $image ) ) {
 ob_end_clean();
 return $bits;
 }
 break;
 
 default;
 ob_end_clean();
 return $bits;
 }
 $bits = ob_get_contents();
 ob_end_clean();
 
 imagedestroy( $image );
 
 return $bits;
 }
 
 // Watermarks an $image
 public function watermark( $image ) {
 
 // Load the watermark into $watermark
 if ( ! $watermark = @imagecreatefrompng( $this->watermark ) ) {
 return $image;
 }
 
 // Get the original image dimensions
 $image_width  = imagesx( $image );
 $image_height = imagesy( $image );
 
 // Get the watermark dimensions
 $watermark_width  = imagesx( $watermark );
 $watermark_height = imagesy( $watermark );
 
 // Calculate watermark location (see docs for help with these filters)
 $dest_x = (int) apply_filters( 'wpcom_watermark_uploads_destx', $image_width - $watermark_width - 5, $image_width, $watermark_width );
 $dest_y = (int) apply_filters( 'wpcom_watermark_uploads_desty', $image_height - $watermark_height - 5, $image_height, $watermark_height );
 
 // Copy the watermark onto the original image
 imagecopy( $image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height );
 
 imagedestroy( $watermark );
 
 return $image;
 }
 
 // Safety wrapper for our get_jpeg_quality() function
 // See http://blog.apokalyptik.com/2009/09/16/quality-time-with-your-jpegs/
 public function get_jpeg_quality_wrapper( $imagecontent ) {
 
 $quality = false;
 
 if ( ! function_exists( 'get_jpeg_quality' ) )
 @include_once( WP_PLUGIN_DIR . '/wpcom-images/libjpeg.php' );
 
 if ( function_exists( 'get_jpeg_quality' ) )
 $quality = get_jpeg_quality( $imagecontent );
 
 return $quality;
 }
 
 // Figure out image type based on filename
 public function get_type( $filename ) {
 $wp_filetype = wp_check_filetype( $filename );
 switch ( $wp_filetype['ext'] ) {
 case 'png':
 return 'png';
 case 'jpg':
 case 'jpeg':
 return 'jpeg';
 default;
 return false;
 }
 }
}
 
// Start this plugin once everything else is loaded up
add_action( 'init', 'WPcom_Watermark_Uploads', 5 );
function WPcom_Watermark_Uploads() {
 global $WPcom_Watermark_Uploads;
 $WPcom_Watermark_Uploads = new WPcom_Watermark_Uploads();
}
 
?>Code language: PHP (php)

Read this post in Spanish: Cómo añadir marcas de agua a tus imágenes fácil y gratis en WordPress

How useful was this post?

Click on a smiley to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Skip to content