Watermark without plugins
-
Hello, I make adding watermark when image is loading into medialibrary. For that I use “add_attachment” hook:
add_action('add_attachment', 'applyWatermark');
My trouble is thumbnails has watermark too. I want that they didn’t have it.
I suspect that need find other hook who will executed after create thumbnail function but I can’t find it. Or exist other way perhaps?Handler function “applyWatermark” if is needed:
function applyWatermark($attachId) { if (wp_attachment_is_image($attachId)) { $attachPath = get_attached_file($attachId); $templatePath = get_bloginfo('template_directory'); $im = imagecreatefromjpeg($attachPath); $stamp = imageCreateFromPng($templatePath.'/watermarks/wm.png'); $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); imageAlphaBlending($stamp, false); imageSaveAlpha($stamp, true); imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp)); imagejpeg($im, $attachPath); imagedestroy($im); } return $attachId; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Watermark without plugins’ is closed to new replies.