Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method SISANU_Emails_Catch_All::load_textdomain() should not be called statically in /home/mbucur/public_html/wp-includes/class-wp-hook.php on line 286
Batch watermarking – Marian Bucur

Batch watermarking

Code:

/**
  * Batch watermarking.
  */
     
require_once('../lib/watermark-my-image.class.php');
require_once('../lib/watermark-my-image-text.class.php');
require_once('../lib/watermark-my-image-icon.class.php');
     
     
// Create a new Watermark_My_Image object with no parameters as we will set the file path later.
$watermark = new Watermark_My_Image();
     
     
// Create a new Watermark_My_Image_text object passing a string as a parameter.
$text = new Watermark_My_Image_Text('Enjoy using Watermark My Image Standalone Class');
     
// Customize the text.
$text->set_color('D3D3D3')
     ->set_size(13);
     
     
// Create a gd resource.
$icon_resource = imagecreatefrompng('images/heart.png');
     
// Colorize the image.
imagefilter($icon_resource, IMG_FILTER_COLORIZE, 211, 211, 211);
     
// Create an icon object using the colorized image.
$icon = new Watermark_My_Image_Icon($icon_resource);
$icon->set_max_height_percentage(60);
     
     
// Customize the watermark, add the text and icon.
$watermark->set_background_color('606060')
          ->set_background_transparency(40)
          ->set_place_inside(true)
          ->add_text($text)
          ->add_icon($icon)
          ->set_icons_offset_y(7);
     
     
$src_dir = 'demo10_src/';
     
     
if ($handle = opendir($src_dir)) {
     
    // Process each file from the directory.
    while (false !== ($entry = readdir($handle))) {
        if (is_file($src_dir . $entry)) {
             // Set the file path to the source image and save the watermarked image to the destination directori.
             $watermark->set_file_path($src_dir . $entry)
                      ->save('demo10_dst/' . $entry);
     
             // Get and display errors.
             $errors = $watermark->get_errors();
     
             if ($errors) {
                 var_dump($errors);
     
                 // Stop the execution if there is any error.
                 die();
             }
         }
    }
}

Result: