Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [GD Lib] Create Watermark

  1. #1
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default [GD Lib] Create Watermark

    how to creates watermark for copyrighted images?

    Like this I mean :

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Watermarks may appear simple, but sometimes are actually complex. It involves placing one image over another then blending them in such a way that they don't really take away from the viewing experience but are very hard to remove. If you just have a white image at a low opacity, it actually would be possible, if someone cared enough, to remove it by re-darkening those areas. The best watermarks remove enough data from the original image (by layering something on top) that it isn't possible to recover it very well, and they also do so in a non-linear fashion.
    Many watermarks use a technique similar to the "overlay" layer mode in Photoshop (and similar graphics programs), which, in short, uses an algorithm not of direct percentage mixing, but rather that calculates based on the pixel values of both layers what the next pixel should be like. It's not that it is particularly different to the eye, but once it isn't a linear combination, it's much harder to extract.
    However, it's not like people are going to work that hard to steal images in general, so having anything may be enough. Using an images with more colors in it than just white, for example, might be one way to encourage them to leave the image alone more, though

    Now, as for doing it with the GD library, there are a few things to consider:
    1. GD is incredibly resource intensive. When you can avoid using it, do so. It's generally a bad idea to run GD on the fly unless it's for a very specific purpose, or very small images. Processing many large images (let's say anything over 200x200px) will not only be slow but also cause a load to your server you probably don't want.
    2. It is a convenience, though, so one way around this is to pre-process with GD-- that is you can dynamically run it on all of your images and then just load the now saved results. That's fine and won't be constantly taxing on the server. You can even setup a php script that will do that automatically if an image has no watermarked version yet to display (a new one) then save that for all future loads. I've done this with thumbnail galleries for images before-- it searches for all the images and grabs their thumbnails, but when it comes across one that has no thumbnail it generates that too then adds the thumbnail to the page just like all the others then will never need to generate it again.
    3. Working with laying in GD can be a pain. It's possible, but probably not something you want to code yourself, at least in a pixel by pixel way. I believe there are some layering functions that may help you, so one option is to create your "watermark" on a black image (that is actually apply it to the black image) in photoshop or whatever, then save that as a file on your server. Your script can then take that watermark and layering it directly (using alpha channels, which are supported by GD) and it's no more work than just layering two images directly-- no complex calculations. Alternatively, you can do actual calculations, but that will be slower/more server-intensive.
    4. This is really a time to use google and look for an existing script. "php gd watermark" should get you there and I'm sure it's something people use GD for somewhat often. This isn't a script you'd want to have to write yourself, nor is it particularly rewarding to have your own version-- it'll end up like what someone else has anyway.

    So I hope that gets you started. Sorry for the vagueness above, but there are a few things you have to figure out to make it all work, like whether you'll pregenerate the images, or actually run it each time they load (usually a really bad idea, unfortunately).
    In the end, one of the easiest answers here is to just process them in Photoshop (etc), even if you have a couple hundred or thousand, perhaps using actions, then upload them. Alternatively, make that script pregenerate them and then not load each time. But do be careful about running it too often/for too long at one time, because I was once using a fairly simple image generator (making a complex gradient, basically) and the hosting account was shut down for server overload. Of course they will probably be understanding, but that kind of server load is not the sort of thing they're used to seeing, and they'll probably ask you to not run it like that again. If you have your own server, that's not much of an issue, though you will still need to worry about time. One option around all of this would be to instead run it locally (either by using your computer as a server, or running php as an exe: http://www.bambalam.se/bamcompile/) then uploading after that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    any ebook for PHP gd library?

    thanks

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I haven't found anything particularly useful. Basically, aside from their potential (in theory they can do lots of cool stuff), the GD functions are a mess and usually worth avoiding, even if just for how confusing they can be if you're not used to them (and few people seem to be-- I've used them more than most around here at least, and it's still an uphill battle to get something to work, not that I'm claiming to be particularly good with them).
    They aren't hard/complex as much as just very strict. The best way I have found to learn is to copy examples, and a lot can be found on php.net documenting each of the functions.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Not that hard. Look at this.
    Please Note: I've md5ed the original, this way users can't find the file unless their smart.
    Jeremy | jfein.net

  6. #6
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Nile's solution was a bit bugged. This is not perfect, but a little better.
    PHP Code:
    <?php
    header
    ('Content-type: image/jpeg');
    $img_src '782f7448d47c544edc346b92ae12140a.jpg';
    $message 'Watermark Test';
    $im imagecreatefromjpeg($img_src);
    $water_mark imagecolorallocatealpha($im00060);
    list(
    $width$height) = getimagesize($img_src);
    imagefttext($im$width strlen($message), 00$height 5$water_mark'arial.ttf'$message);
    imagejpeg($im);
    imagedestroy($im);

  7. #7
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    yeah, it works, niceee, thanks a lot

    $img_src = "782f7448d47c544edc346b92ae12140a.jpg"; (the file's name)

    Is it possible to detect the file's name using GDLibrary?

    Ex :
    FaceBook :
    - Johan.jpg
    - Micheal.jpg
    - Christina.jpg

    I wanna make a watermark, using it's file name from FaceBook folder, and then "REPLACE" the original

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't really understand what you are saying. You cannot reverse md5-- that's not possible, and that's the point of the algorithm-- it's one way. But you could store that filename while you're converting it and then delete the original with that name after it's been converted. However, I don't see the point-- just create a copy folder and only put those on the website. That way you'll always have a backup of the originals if you want to change the watermark, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    http://md5crack.com

    Can hack them
    ___________________________________

    Still working on it!

  10. #10
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Quote Originally Posted by Dirt_Diver View Post
    http://md5crack.com

    Can hack them
    That might technically be hacking, but if so, you can do the same thing with any hash.

    And that is thwarted by not using 'password' for your password. Or generally not hashing words from the dictionary in the first place.

    Crack this: 5cea7395e83dcfc3bb87f2b45f5422d6

Tags for this Thread

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
  •