SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast [Az]'s Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image watermarking in inline HTML

    I've written a function that will automatically watermark an image display it on-screen. Realistically though, I need the watermarked image to appear at any given point on an HTML page and the function uses the header code to set the type so it can only exist on it's own. I changed the function to create the watermarked image and then save it to another file and use readfile to pull that through into the correct place but that necessitates me having to save the watermarked image on the server which I don't want to have to do.

    Is there anyway to watermark an image and then display it at any point on a page without having to save the image to disk first ?
    HEXUS Webmaster

  2. #2
    SitePoint Zealot sleepeasy's Avatar
    Join Date
    Sep 2003
    Location
    Bristol, UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Point the src attribute of the image tag to the script that watermarks the image, :

    HTML Code:
    <image src="watermark.php?image=foo.jpg">
    watermark.php

    PHP Code:
    yourWatermarkFunctionWithHeaders($_GET['image']); 
    Note you should check that $_GET['image'] is set and is valid (that the image exists etc.) I would also suggest that you cache the generated image.
    Always open to question or ridicule

  3. #3
    SitePoint Enthusiast [Az]'s Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats already how I'm doing it as stated (confusingly) above). THe only way I can return the image though is using readfile() which necessitates that the image be on disk somewhere. Ideally I don't want to have to create the image and save it in order to display it
    HEXUS Webmaster

  4. #4
    SitePoint Enthusiast [Az]'s Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump
    HEXUS Webmaster

  5. #5

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use imagejpeg to output the image data directly to the client.

    PHP Code:
    $img=imagecreatefromjpeg($_GET['image']);
    // do your watermarking here
    header("Content-Type: image/jpeg");
    imagejpeg($img); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •