Text Water Mark On Image (on Fly/on Access)

Discussion in 'PHP' started by KingCobra, Feb 16, 2013.

  1. #1
    Dear friends,
    I need a help about image watermarking. I want to use text watermarking on fly/on call/on access an image. The following code works fine (if GD enabled). But the page that shows the watermarked image don't allow me to put another texts/ html codes etc. Actually I want to display the watermarked image on a page where there are many other html contents. So please tell me how can I do that or if you have another solution then PLEASE PLEASE tell me. Thanks in advance.

    <?php
    //load image
    $im = imagecreatefromjpeg('img.jpg');
     
    //figure out where to put the text
    $imagesize = getimagesize('img.jpg');
    $x_offset = 7;
    $y_offset = $imagesize[1] - 20;
     
    //allocate text color
    $textcolor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
     
    //write out the watermark
    imagestring($im, 5, $x_offset, $y_offset, 'My watermark', $textcolor);
     
    //output watermarked image
    header('Content-type: image/jpg');
    imagejpeg($im);
     
    ?>
    Code (markup):

     
    KingCobra, Feb 16, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Could you try explaining that in a bit more detail? I cannot for the life of me even figure out what you are asking for... "But the page that shows the watermarked image don't allow me to put another texts/ html codes" -- that bit of broken engrish in particular I cannae make the least bit of sense out of.
     
    deathshadow, Feb 17, 2013 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    You will need to have an intermediate page. Let's say the above code is in image.php, you will show the user the page showImage.php, which includes your HTML/PHP and then the image.php image:

    
    <?php
    echo 'Your image <img src="image.php" />';
    
    PHP:
     
    ThePHPMaster, Feb 17, 2013 IP
  4. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #4

    If you'd pay a bit more attention to what he asks for, you'd understand as we all did that the user wanted to include some "html code" besides the image itself on the respective page. Though, that's not possible since you're sending a content-type : "image/jpg" or whatever. As the above users commented, you need to include the image in the page you're needing it to be by using either <img src , either some div with a background-image from css.
     
    edduvs, Feb 18, 2013 IP