{"id":5915980,"date":"2015-03-19T06:41:47","date_gmt":"2015-03-19T06:41:47","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/watermark-without-plugins\/"},"modified":"2016-08-22T18:13:12","modified_gmt":"2016-08-22T18:13:12","slug":"watermark-without-plugins","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/watermark-without-plugins\/","title":{"rendered":"Watermark without plugins"},"content":{"rendered":"<p>Hello, I make adding watermark when image is loading into medialibrary. For that I use &#8220;add_attachment&#8221; hook:<br \/>\n<code>add_action(&#039;add_attachment&#039;, &#039;applyWatermark&#039;);<\/code><br \/>\nMy trouble is thumbnails has watermark too. I want that they didn&#8217;t have it.<br \/>\nI suspect that need find other hook who will executed after create thumbnail function but I can&#8217;t find it. Or exist other way perhaps?<\/p>\n<p>Handler function &#8220;applyWatermark&#8221; if is needed:<\/p>\n<pre><code>function applyWatermark($attachId)\n{\n  if (wp_attachment_is_image($attachId)) {\n\n    $attachPath = get_attached_file($attachId);\n    $templatePath = get_bloginfo(&#039;template_directory&#039;);\n\n    $im = imagecreatefromjpeg($attachPath);\n    $stamp = imageCreateFromPng($templatePath.&#039;\/watermarks\/wm.png&#039;);\n\n    $marge_right = 10;\n    $marge_bottom = 10;\n    $sx = imagesx($stamp);\n    $sy = imagesy($stamp);\n    imageAlphaBlending($stamp, false);\n    imageSaveAlpha($stamp, true);\n\n    imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));\n\n    imagejpeg($im, $attachPath);\n    imagedestroy($im);\n  }\n\n  return $attachId;\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-5915980","topic","type-topic","status-closed","hentry","topic-tag-hook","topic-tag-watermark"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5915980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5915980\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5915980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}