Beginner PHP Tutorial – 163 – Watermarking Images Part 3

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

15 responses to “Beginner PHP Tutorial – 163 – Watermarking Images Part 3”

  1. ALi و NiDAL Avatar

    here is a working source:

    <?php

    header ('Content-type: image/jpeg');

    if(isset($_GET['source'])){
    $source = $_GET['source'];

    $watermark = ImageCreateFromPng('logo.png');
    $watermark_w = ImageSx($watermark);
    $watermark_h = ImageSy($watermark);

    $image = ImageCreateTrueColor($watermark_w,$watermark_h);
    $image = ImageCreateFromJpeg($source);

    $image_size = GetImageSize($source);
    $x = $image_size[0] – $watermark_w – 50;
    $y = $image_size[1] – $watermark_h – 10;

    ImageCopyMerge($image, $watermark, $x, $y, 0, 0, $watermark_w, $watermark_h, 100);
    ImageJpeg($image);
    }
    ?>

  2. Andy unknown Avatar

    for transparent watermarks try:
    imagealphablending($image,true);
    imagesavealpha($image,true);
    imagecopy($image,$watermark,$x,$y,0,0,$watermark_width,$watermark_height);
    instead of:
    imagecopymerge($image,$watermark,$x,$y,0,0,$watermark_width,$watermark_height,50);

    however, the opacity effect does not work then…

  3. Dan Howell Avatar

    I get a small page-like icon upper right corner, instead of my image and watermark? Any clues why, please help…thank you!

  4. Arjan Treur Avatar

    I only watched the video, but I was thinking the same Zeryab. The second declaration of $image overwrites the first one, so the first declaration ($image = imagecreatetruecolor($watermark_width, $watermark_height)) doesn't do anything anymore. So my guess is you can just leave it out.

  5. zeryab hassan Kiani Avatar

    What is the purpose of this line can anybody please tell me
    $image = imagecreatetruecolor($watermark_width , $watermark_height);

    My code is running perfectly without this too

  6. Sammy Stone Avatar

    For some reason i cannot use properly GD library, i cannot use jpeg, nor png files, i have typed the code correctly, and i am only getting error messages, i really need help, if anyone wants to explain to me how to create watermarking, step by step, please answer me. I am using Wamp, and PHP 5.5.12, the latest version for Windows 8.1

  7. Tim Broders Avatar

    For some reason, I have the exact same code but jpg files don't work. I had to use png files for all of the pictures and functions. 

  8. MGApcDev Avatar

    Don't merge with a .png that has transparent background, the picture gets messed up.

  9. alex dimitrevski Avatar

    if you could make video that explaines how working this last part,but correctly working that doesn't work on your video,i mean on those last 2 minutes,when generate new pic with watermark.

  10. chillfill Avatar

    need a little help!!!
    getimagesize() is not working in my case (i am using WAMP )
    it returns 0 as height and width.
    php manual says that
    "Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases. "

  11. Randy Gonzales Avatar

    If it doesn't work even xampp is installed, check your speelings in your script maybe that's the problem like mine 🙂

  12. sutistalica Avatar

    "$image=imagecreatetruecolor(……, …..)"

    this is not required….
    anyway thanks for the tutorial..

  13. Nathan Chambers Avatar

    you should have exploded the filename and removed the extension before saving it so its hone.watermarked.jpg not phone.jpg.watermarked.jpg huh? 😛 none the less good vid 🙂

  14. Zhuoyan Xu Avatar

    Haha, good finding…haha Thanks alex.

Leave a Reply

Your email address will not be published. Required fields are marked *