php - Add transparent watermark into image -


I need to add transparent watermarks (transparency in the final image - 80%) I have created this function to handle it :

  function image adapter ($ im, $ stamp, $ onLeft, $ on Top, $ margin) {// $ stamp = imagecreatformpng (...) - & gt; GD Resources? // Not important part - it calculates the watermark status ($ onLeft) {$ orgX = $ margin; } And ($ orgX = imagesx ($ im) - $ margin-images ($ postage stamp);} if ($ on top) {$ orgY = $ margin;} and ($ orgY = imagesy ($ im) - $ margin - Images ($ postage stamp);} Imagecopymerge ($ im, $ stamp, $ orgx, $ orgY, 0, 0, images ($ postage stamps), images ($ postage stamp), 50); return $ IM;} < / Code> 

The result of the function: error

but imagecopymerge Instead of transparent, gives a black background. I also heard some opinions that the image code is perfect for creating a transparent watermark. The question is: "How do I add a transparent watermark (use alpha?) In a JPG picture?" How can I get rid of that black backdate? (is transparent in the original PNG file)

OK, I got the solution:

function image adapter ($ im, $ stamp, $ onLeft, $ on Top, $ margin) {

  if ($ OnLeft) {$ orgX = $ margin; } And ($ orgX = imagesx ($ im) - $ margin-images ($ postage stamp);} if ($ on top) {$ orgY = $ margin;} and ($ orgY = imagesy ($ im) - $ margin Images ($ postage stamp);} // Build a cut resource $ cut = imagecreatetruecolor (imagesx ($ stamp), images ($ stamp)); // copy copy cut from background to image processing ($ cut, To copy the cut image of the $ im, 0, 0, $ orgX, $ orgY, images ($ tickets), images ($ tickets)) // section related to watermarks ($ cut, $ stamp, 0, 0, 0, 0, images ($ da Tickets), images ($ postage stamp)) // destination image imagecopymerge ($ im, $ cut, $ orgX, $ orgY, 0, 0, images ($ postage stamp), images ($ postage stamp), 50); Return $ IM;}  

Comments