Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#394 Incrustation of text in images (watermarking)

open
Larry Meaney
5
2007-09-05
2007-06-19
No

This patch is made to inscrust some text in images when those are displayed in PGV.
Files and readme.txt arein zip file attached,
Andre

ps: made to run with 4.0.x version, not tested with earlier or more recent versions

Discussion

  • Gerry Kroll
    Gerry Kroll
    2007-06-21

    Logged In: YES
    user_id=1198414
    Originator: NO

    I've replaced the original .ZIP file. "imgtext.php" was accidentally saved as a UTF-8 file with BOM. The BOM caused your "output already started" error.
    File Added: imgtext.zip

     
  • Larry Meaney
    Larry Meaney
    2007-07-04

    Logged In: YES
    user_id=45016
    Originator: NO

    This is pretty cool!

    I ran into a problem... my server doesn't have imagettftext available so I was getting errors. I added this to the top of imgtext.php:

    $blnUseImagettftext = (function_exists("imagettftext")) ? 1 : 0;
    if (!$blnUseImagettftext) {
    $word1_rotation = 0;
    $word2_rotation = 0;
    }

    And then wrapped the calls to imagettftext like this:

    if ($blnUseImagettftext) {
    imagettftext($temp_im, $taille, $word1_rotation, $pos_x, $pos_y, $textcolor, $font, stripslashes($word1_txt));
    } else {
    imagestring($temp_im, 5, $pos_x, $pos_y, stripslashes($word1_txt), $textcolor);
    }

    so if imagettftext isn't available it will use imagestring. Unfortunately, imagestring can't rotate images, which is the reason for setting the rotations to 0 at the top.

    Oh, I also had to make sure $pos_x is defined when there is no rotation:

    if ($word1_rotation != 0) {
    <snip>
    } else {
    $pos_x = 1;
    }

    Hope it helps,

    -larry

     
  • Larry Meaney
    Larry Meaney
    2007-07-08

    Logged In: YES
    user_id=45016
    Originator: NO

    The main problem with this solution is that the untainted files are still available in their original locations, and it is quite easy to get to them.

    I just submitted a patch:
    https://sourceforge.net/tracker/index.php?func=detail&aid=1739602&group_id=55456&atid=477081
    to add a "media firewall" to PGV, which allows you to put the media files outside of the web root.

    Once that has been implemented, the concepts from this patch could be added to the firewall, and text could be embedded in the images on the fly.

     
  • Logged In: YES
    user_id=943927
    Originator: YES

    I just attached a new version (0.3) of this media text incrustration patch.
    Many changes:
    - positions of the parts of text are computed from angle of the diagonal.
    - auto-delation of pasted files seemed to dysfonction on certain configurations
    - pgv variables can be used instead of text
    - i tried to insert Larry's code on server where imagettftext is not available (let him tell il it works allright)
    ...
    Be carefull, config file changed !
    I do not agree with ljm; i included an example of a .htaccess file that can be used to ban access to media folders except thumbs folder. As images are shown from a folder that is not the folder where images are stored, it seems possible to avoid access to those folders.
    André

    ps: i use Notepad++ to write php scripts and it seems utf8 without bom 's not allways working good. Hope these file do not contain bom ?

    File Added: imgtext v0_3.zip

     
  • Gerry Kroll
    Gerry Kroll
    2007-07-09

    Logged In: YES
    user_id=1198414
    Originator: NO

    André's file is in ZIP format, but wasn't named correctly. SourceForge doesn't permit spaces in file names.

    I have corrected this.
    File Added: imgtext.zip

     
  • KosherJava
    KosherJava
    2007-08-03

    Logged In: YES
    user_id=634811
    Originator: NO

    Will this be merged to the media firewall in 4.2?

     
  • Larry Meaney
    Larry Meaney
    2007-08-04

    Logged In: YES
    user_id=45016
    Originator: NO

    Yes! I do plan to incorporate this into the media firewall. Can someone assign this patch to me? I don't have any options to do that.

     
  • KosherJava
    KosherJava
    2007-08-05

    • assigned_to: nobody --> ljm
     
  • Larry Meaney
    Larry Meaney
    2007-08-05

    Logged In: YES
    user_id=45016
    Originator: NO

    Hi Avdl!

    Your text embedding functions are awesome!

    I have tweaked things a bit and added this as a module to be used with the media firewall. The media firewall is now designed to pass an image resource to the watermark_text module, which does its thing and returns an image resource back to the media firewall to serve to the user.

    The idea is that we could eventually have multiple watermarking modules that watermark in different ways, but they would all be plugins for the media firewall. I plan to add more about this to the wiki:
    http://wiki.phpgedview.net/en/index.php/Media_Firewall

    I've got one question for you... can you tell me what "taille" means in English?

    I am having a very hard time understanding how this function works:

    function textlength($t,$mxl,$text) {
    $taille_c = $t;
    while (($taille_c-2)*(strlen(stripslashes($text))) > $mxl) {
    $taille_c--;
    if ($taille_c == 2) break;
    }
    return ($taille_c);
    }

    It is determining the size of the font to use, right? how? LOL :) I want to modify it to take into account the size of the image, so that the font size will be larger on large images. If you've got ideas on how to do that, I'll gladly listen :)

    thanks!

    -larry

     
  • Logged In: YES
    user_id=943927
    Originator: YES

    Hello Larry,
    i'm glad you find this module useful and i'll try to answer your questions:
    > I've got one question for you... can you tell me what "taille" means in
    English?
    Yes, $taille is the variable that is calculated to determine font size

    > I want modify it to take into account the size of the image, so that the font
    size will be larger on large images. If you've got ideas on how to do
    that, I'll gladly listen :)
    but IT ALLREADY DOES ?
    just look at this photo:
    http://www.ghezibde.net/genealogie/medialist.php?action=filter&search=yes&filter=&folder=media%2Fmalesys-sohier%2F&max=20#
    and now at this one:
    http://www.ghezibde.net/genealogie/medialist.php?action=filter&search=yes&filter=&folder=media%2Fmalesys-sohier%2F&max=20#
    Size is automatically computed for the sentence to fit in the document.4

    There has been two versions of this module; there are differencies for this calculation:
    - in first version evaluated size was depending on width OR height
    - in second version, size is evaluated depending on width AND height (with arccos)

    A third version is in preparation; this second version has a bug, text watermarking does not work with bmp files. I do not use bmp files but a user just uploaded one last week and i saw it did not work. I had a look and i now understatd why: i made a confusin between wbpm and bmp file types.
    i know how to manage it but won't be able to work on it this week; i'll be there before the end of august.
    If you have a attentive look at the last version, you'll remark i added a .htaccess file to put in the media root; to me nobody is able to get my original media files anymore ?

    I'll try to spare time to have a look at your firewall module and i'll then tell you if i prefer my module to continue to work on its own or if it's better to me to make a plugin of it.
    Best regards,
    Andre

     
  • Logged In: YES
    user_id=943927
    Originator: YES

    Hello Larry,
    i'm glad you find this module useful and i'll try to answer your questions:
    > I've got one question for you... can you tell me what "taille" means in
    English?
    Yes, $taille is the variable that is calculated to determine font size

    > I want modify it to take into account the size of the image, so that the font
    size will be larger on large images. If you've got ideas on how to do
    that, I'll gladly listen :)
    but IT ALLREADY DOES ?
    just look at this photo:
    http://www.ghezibde.net/genealogie/medialist.php?action=filter&search=yes&filter=&folder=media%2Fmalesys-sohier%2F&max=20#
    and now at this one:
    http://www.ghezibde.net/genealogie/medialist.php?action=filter&search=yes&filter=&folder=media%2Fmalesys-sohier%2F&max=20#
    Size is automatically computed for the sentence to fit in the document.4

    There has been two versions of this module; there are differencies for this calculation:
    - in first version evaluated size was depending on width OR height
    - in second version, size is evaluated depending on width AND height (with arccos)

    A third version is in preparation; this second version has a bug, text watermarking does not work with bmp files. I do not use bmp files but a user just uploaded one last week and i saw it did not work. I had a look and i now understatd why: i made a confusin between wbpm and bmp file types.
    i know how to manage it but won't be able to work on it this week; i'll be there before the end of august.
    If you have a attentive look at the last version, you'll remark i added a .htaccess file to put in the media root; to me nobody is able to get my original media files anymore ?

    I'll try to spare time to have a look at your firewall module and i'll then tell you if i prefer my module to continue to work on its own or if it's better to me to make a plugin of it.
    Best regards,
    Andre

     
  • Larry Meaney
    Larry Meaney
    2007-08-05

    Logged In: YES
    user_id=45016
    Originator: NO

    Hi Andre,

    > but IT ALLREADY DOES ?

    hmm... so it does :) Have you tried it on any images that are rather large, like 2000 pixels high and wide? The text is a lot smaller on those images than it is on a 500 pixel image. When I saw that I assumed it wasn't taking the image size into account.

    What does "taille" mean?

    thanks!

    -larry

     
  • Logged In: YES
    user_id=943927
    Originator: YES

    have you check $word1_fsize setting in imgtext/config.php ?
    this setting tells the module the max fontsize to use.
    It works for me
    Seems you did set a too small value for it.
    I set it to 90; give a try to 200, anyway if it's too big, it'll be automatically reduced.

    in
    it's said:
    - parameter $word1_fsize
    maximum size of the sentence "word1";
    will be automaticaly reduced to fit in the image if necessary
    (i.e. $word1_fsize = 60;)
    did you read it ?

    I asked you another question in my message:
    what about my .htaccess that seems the best firewall to me ?

    Happy to hear about your tests,
    Andre

    it would perhaps be better to exchange by mail, mine is vert2rage <at> yahoo <dot> fr

    taille means size.

     
    • summary: Incrustation of texte in images --> Incrustation of text in images (watermarking)
     
  • Logged In: YES
    user_id=943927
    Originator: YES

    version 0.4 arrives !
    What changed:
    - watermarking works now for bmp files also (not yet psd, but their size is so big, i wonder if it's worth spending time ? ... just tell me)
    - cleaning temporary folder works better
    - watermarking thumbnail files is now possible; watermarked thumb files are not stored in a specific location; as thumbnail media files are not original files, patch alter the way PGV generates its own thumbnail media files; a specific config files is there to store parameters for this)
    - watermarked files for bmp, gif, png are now stored in jpg format, allreay treated files is correctly done
    - installation for PGV 4.1 version AND 4.0.x is explained in txt file
    - many other improvments

    Andre

    ps: don't forget to copy the .htaccess stored in zip file in your media folder, this way nobody can access to your media files outside of pgv !

    ps2: i tried to exclude all bom characters of the files using the editor Gerry told me, hope it's good ?
    File Added: imgtext.zip

     
  • Watermarking media files v0.4

     
    Attachments
  • Larry Meaney
    Larry Meaney
    2007-09-14

    Logged In: YES
    user_id=45016
    Originator: NO

    Hi Andre,

    Version .4 is really taking this in a different direction than I want to go with the Media Firewall. In some areas it competes with the Media Firewall, and if it works for you, that is great! But using this as a stand-alone module without the Media Firewall has several disadvantages:

    * With this module, the url to each images changes from:
    /pgv/media/path/image.jpg
    to
    /pgv/affidir/image.jpg
    This is a fundamental difference between the two approaches. This module compensates for the url change by modifying mediaview.php but it doesn't fix the urls in media.php, medialist.php, the slideshow module or the new album module (there may be more). On the other hand, the Media Firewall doesn't change the url that is used to view an image, so any existing link to a media file will continue to work.

    * With this module, watermarks are applied to images but nothing is done to ensure private images stay private. A fundamental difference is that the Media Firewall uses all the power of PGV's permissions to determine whether the current user can even view an image.

    * With this module, all users see the watermarked images. With the Media Firewall, the admin can specify who sees watermarks based on their user level: public/authenticated/admin

    * With this module, there is no differentiation between duplicate names in different paths. The watermarked versions of:
    /pgv/media/path1/sample.jpg
    and:
    /pgv/media/path2/sample.jpg
    are both written to:
    /pgv/affidir/sample.jpg

    Hmm... I didn't mean for this to be all negative! I really appreciate the work that went into generating the watermarks; your code for writing diagonal text and determining font size is genius (I still don't fully understand it!)

    If you can setup a spare system, I encourage you to try out the Media Firewall in SVN 4.2. Or, you can wait a little longer (a week or two maybe?) and it will be added to SVN 4.1.2

    I updated the Media Firewall documentation tonight to bring it up to date with the latest info:
    http://wiki.phpgedview.net/en/index.php/Media_Firewall

    -larry

     
  • Logged In: YES
    user_id=943927
    Originator: YES

    Hello Larry,
    I do not want to argue wether this patch does or doesn't do this or that.
    It was only made to incrust text in photos when showing them and thus avoid files to be downloaded and reused elsewhere not knowing where they came from.
    It does not claim to be a "firewall" image tool but if it can take part in the tool you're preparing, that's allright, be sure you can count on my assistance to succeed !

    Later, if i think this patch has an interest to be used as a stand alone tool besides, i will think about it.

    I didn't try media firewall for now, i'll do it soon,
    Best regards,
    André