SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    watermark a Image with 1) Text 2) Image

    I would like to know how to watermark image through php. Any examples suggestions that explain what i would like to learn(listed bellow) are welcome

    1) Text
    How to watermark an image with text.
    Set font
    Set font color
    Set font size
    align text - top left, top center, top right, bottom left, center center etc...
    set margins
    set opacity

    2) Image
    How to watermark an image with image.
    align image - top left, top center, top right, bottom left, center center etc...
    set margins
    set opacity

    Any help greatly appreciated.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    google it.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried, none of which explains some aspects such as margins, alignment etc.

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you don't use margins - you use co-ordinates.

    http://www.sitepoint.com/article/watermark-images-php
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,443
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    I have some examples on my site using ImageMagick check out my signature. I think its easyer done in IM than GD.

  6. #6
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is more or less what i'm after for image watermarks, but there are two problems, when used a transparent image as watermark image - it doesn't work with transparency and in addition the whole image is blurred a little. Any suggestion how to work around these two problems?

  7. #7
    SitePoint Member
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very interesting, I'd wanted to know this myself. Glad you posted it here.
    Free Internet Business Videos, Tips and
    Podcast at The Unstoppable Profits Blog:

    Click Here To Visit The Unstoppable Profits Blog

  8. #8
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    I have some examples on my site using ImageMagick check out my signature. I think its easyer done in IM than GD.
    Sounds good, i'll go through it

    [edit]
    It seems it's not helping me much.
    Last edited by cssExp; Oct 12, 2007 at 09:28.

  9. #9
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright i got everything right(image watermark), only doubt is that, is there a way to set opacity of watermark image without imagecopymerge? cause using imagecopymerge with 24-bit png file causes graphic problems.

  10. #10
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's when you turn to an outside graphics package, like ImageMagick. GD is a relatively basic library and it won't fulfill all needs.

  11. #11
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    That's when you turn to an outside graphics package, like ImageMagick. GD is a relatively basic library and it won't fulfill all needs.
    Great, but searching on Google brings up even less help than any GD examples etc... could you point me to any proper examples? thanks

  12. #12
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ImageMagick seems unnecessarily complicated, only command line codes out there.

    So is there no way to maintain quality of a 24-bit transparent image with 'imahecopymerge'?

    if so, is it possible to set opacity of the watermark image before using 'imagecopy'?

  13. #13
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well, it's a set of command line utilities. That doesn't make it more complicated than writing code

    Mess around with imagealphablending() and imagesavealpha(). Might find something that works for you.

  14. #14
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the following.

    Code PHP:
    header('content-type: image/png');
     
    $sourcefile = imagecreatefromjpeg('image.jpg'); // a  big jpg image
    $watermark = imagecreatefrompng('logo.png'); // 24-bit transparent image
     
    imagealphablending($sourcefile, true);
     
    imagecopy($sourcefile, $watermark, 5, 5, 0, 0, 248, 143);
     
    imagepng($sourcefile);
     
     
    imagedestroy($sourcefile);
    imagedestroy($watermark);

    It works great, the 24-bit png also preserves it's transparency and quality. But i also want to set opacity for $watermark. Doing the following solves the opacity problem.


    Code PHP:
    header('content-type: image/png');
     
    $sourcefile = imagecreatefromjpeg('image.jpg'); // a  big jpg image
    $watermark = imagecreatefrompng('logo.png'); // 24-bit transparent image
     
    imagealphablending($sourcefile, true);
     
    $setOpacity = 50;
     
    imagecopymerge($sourcefile, $watermark, 5, 5, 0, 0, 248, 143, $setOpacity);
     
    imagepng($sourcefile);
     
     
    imagedestroy($sourcefile);
    imagedestroy($watermark);

    but in this case the 24-bit png becomes non-transparent and also looses quality, sort of becomes like a crayon drawing. Any viable, simple solution?

  15. #15
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Did imagesavealpha() not change anything?

  16. #16
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Did imagesavealpha() not change anything?
    following didn't make difference.

    Code php:
    header('content-type: image/png');
     
    $sourcefile = imagecreatefromjpeg('image.jpg'); // a  big jpg image
    $watermark = imagecreatefrompng('logo.png'); // 24-bit transparent image
     
    imagealphablending($sourcefile, false);
    imagesavealpha($sourcefile, true);
     
    $setOpacity = 50;
     
    imagecopymerge($sourcefile, $watermark, 5, 5, 0, 0, 248, 143, $setOpacity);
     
    imagepng($sourcefile);
     
     
    imagedestroy($sourcefile);
    imagedestroy($watermark);

  17. #17
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went through ImageMagick, it doesn't seem to be as hard as i thought , or rather i'm quick at grasping things, but unfortunately my web host has ImageMagick disabled. I'm currently messing around with GD so if anyone have any inputs regarding this, i greatly appreciate, It's not about helping me alone - others seeking this also will benefit from this thread after all.


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
  •