SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Watermarks

  1. #1
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Watermarks

    PHP + GD 2.0

    So is it impossible to get a good looking image as a watermark? Like one with transparency or is it just not supported?

    Every image I try to put as a watermark ends up being horrible quality. Especialy when trying to use transparency.

    Is there any way to get good quality watermarks on an image using php?


    Here is my code
    PHP Code:
    <?PHP

    header
    ('content-type: image/jpeg');
    $image2mark "cover_thumb.jpg";
    $watermark imagecreatefromgif('sm.gif');

    $watermark_width imagesx($watermark);  
    $watermark_height imagesy($watermark);

    $image imagecreatefromjpeg("$image2mark");

    $size getimagesize($image2mark);

    $dest_x $size[0] - $watermark_width 5;  
    $dest_y $size[1] - $watermark_height 5;

    imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);

    imagejpeg($image);  
    imagedestroy($image);  
    imagedestroy($watermark);

    ?>

  2. #2
    SitePoint Mentor silver trophy
    SitePoint Award Recipient Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    1,503
    Mentioned
    37 Post(s)
    Tagged
    2 Thread(s)
    Use ImagMagick

    To be honist I have not compaired them but give it a go if you have ImageMagick installed.

    This will add a greyscale watermark to the center of your image:
    PHP Code:
    <?php
    exec
    ("/usr/local/bin/composite -watermark 30% -gravity center watermark_image.gif image_to_watermark.jpg output.jpg");
    ?>
    If you do not have ImageMagick installed and want to get me to try something send me your images and I will try it out, you could then hassel your hosts to install it if you like the results.

  3. #3
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are using imagejpeg, as you probably know, jpeg uses quality ranging from 0-100.
    In case of your script, use this:
    imagejpeg($image,NULL,100);

    For more information:
    http://php.net/manual/en/function.imagejpeg.php
    Last edited by Kokos; Apr 26, 2007 at 12:51. Reason: Added extra link.

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by manipura View Post
    ...
    PHP Code:
    ...
    $watermark imagecreatefromgif('sm.gif'); 
    There's a thing with palettes and GD. When the image is created from a GIF, it has a `restricted` palette of only 256 colors, and this sometimes results in weird results. Anyway, why don't you try Asido? If you go to the Asido website, you can see examples of how to apply watermarks, and you can see how the result looks like: like
    this one (on watermark gravity) and this one (on watermarks from GIFs and JPEGs)

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
  •