How can I add an image onto an image in PHP like a watermark

前端 未结 2 1926
盖世英雄少女心
盖世英雄少女心 2020-12-11 11:44

I am trying to write a small php function to take an image and apply a watermark type image on top of the image and them save them as 1 image, this code runs with 0 errors b

相关标签:
2条回答
  • 2020-12-11 12:10

    Here's a tutorial on how to make it from a watermark using a transparent PNG image: http://www.sitepoint.com/article/watermark-images-php/

    I've used that before and it works. The issue with the code you have is probably that you're trying to generate a jpeg, but the file extension is a gif, so it's not rendering correctly. Could be be wrong though.

    If it's just not saving out a final image, then that's just a permissions problem with the folder. In which case, you most likely have to set the folder to 777 via chmod.

    0 讨论(0)
  • 2020-12-11 12:18

    I think you need to change this (here is a simple tutorial http://www.cafewebmaster.com/image-watermark-php):

    //Add watermark to the image
    if (!(imagecopy($image, $watermark, $watermark_x, $watermark_y, 0, 0, $watermark_w,
        $watermark_h)))
    

    with:

    //Add watermark to the image
    if (!(imagecopymerge($image, $watermark, $watermark_x, $watermark_y, 0, 0, $watermark_w,
        $watermark_h, 100)))
    

    or use wideImage ;)

    0 讨论(0)
提交回复
热议问题