SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GD + Overlay watermark

    Hi,

    Im trying to watermark my images on upload.

    The images are uploading but not getting watermarked.

    Mutliple images are uploaded, then I am trying to watermark them, then continue to create thumbs and resize images.

    Here is the part of code for watermark:

    PHP Code:
        $filetype $photos_uploaded['type'][$counter];
        
    $extention $known_photo_types[$filetype];
        
    $filename $new_id.".".$extention;

        
    mysql_query("UPDATE gallery SET photo_name='".$filename."' WHERE photo_id='".$new_id."'" );

        
    copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);  

        
    $margin 5;
        
    $watermark imagecreatefrompng('watermark.png');
        
    $w getimagesize('watermark.png');

        
    $function_suffix $gd_function_suffix[$filetype];
        
    $Create 'ImageCreateFrom' $function_suffix;
        
    $Save 'Image' $function_suffix;

        
    $image $Create($images_dir."/".$filename);
        
    $image_size getimagesize($images_dir."/".$filename);

        
    $dest_x $size[0] - $w[0] - $margin;
        
    $dest_y $size[1] - $w[1] - $margin;

        
    imagecopy($image$watermark$dest_x$dest_y00$w[0], $w[1]);
        
    imagedestroy($image);
        
    imagedestroy($watermark);
                             
        
    $size GetImageSize$images_dir."/".$filename );

        
    $Config_tbwidth_wide 85;
        
    $Config_tbheight_wide 85;

        
    $Config_tbwidth_tall 85;
        
    $Config_tbheight_tall 85
    Thanks
    Last edited by _matrix_; Jul 22, 2007 at 00:55.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure that $size variable is declared above the given code but i saw something variable typo:
    PHP Code:
        $image $Create($images_dir."/".$filename);
        
    $image_size getimagesize($images_dir."/".$filename);
        
        
    $dest_x $size[0] - $w[0] - $margin;
        
    $dest_y $size[1] - $w[1] - $margin
    PHP Code:
        $image $Create($images_dir."/".$filename);
        
    $image_size getimagesize($images_dir."/".$filename);
        
        
    $dest_x $image_size[0] - $w[0] - $margin;
        
    $dest_y $image_size[1] - $w[1] - $margin
    Umm! I not sure.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Ahh true that.

    I have set

    $size = GetImageSize( $images_dir."/".$filename );

    Still no watermark or errors tho.


    Cheers

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just messed up with your code so i tried myself with my example test images the following code does works me fine. So i hope this will help you.
    PHP Code:
    header("Content-type: image/jpeg");
    $original_file "theimage.jpg";

    $margin 5;

    $watermark imagecreatefrompng('watermark.png');
    $w imagesx($watermark);
    $h imagesy($watermark);

    $image imagecreatefromjpeg($original_file);
    $width imagesx($image);
    $height imagesy($image);

    $dest_x $margin;
    $dest_y $margin;

    imagecopy($image$watermark$margin$margin00$w$h);

    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Seems to give a strange print out on the screen when exicuted:

    Code:
    ?JFIF?CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ?    $.' ",#(7),01444'9=82<.342?  2!!22222222222222222222222222222222222222222222222222? "? ?}!1AQa"q2???#B??RѰ$3br? &#37;&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz???????????????????????????????????ƒąƇȉʒӔՖטٚᢣ䥦稩걲��?? ?w!1AQaq"2?B????#3R��ъ$4ᥱ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz????????????????????????????????????ƒąƇȉʒӔՖטٚ⣤妧詪��????? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (?? (??i ?4??L??Ŕ??凥?O������???? (???(??)?QERRш???(??`QEQEQEQEQEQEQEQEQEQE (??Q@ ?2*?^ ?{???Xrꈇ?bՑ?0М??Gx?ެ$෤??8=震QFh?E???????jјa2<&#187;?үDh?ɠz?s?ڛ?L?E?B넎ҝ��?N??dz"౜⧚?E'?헸Ƿ?E?u!???( Ĩ�&??՚֢dE ?v?cԡ��fuqx?wa?Ymm䜗??̾?r!?3?o܊?}I???30Qɧr?s3?]] )Ϋ?��??I驚w'춡?0?絊곀???aԊɫ?x莶��???ը?Y=?EkǶ?ц/RG餷p2?l~?엦P��>V㍙??c??-??䀎>??4??6???Ē&#225;?ǭkhާ?@??Tմ ?3ٳƘ?!?t@ߧs냱7g?隊??:?evs?c] ??㯥y?8)#G9??W彿Ω笩䷐??Ο?mхy?{,',J?z1??I躚hM?u= .G?r鬸pHࠧ?\pyUY?tu???*?ܩj?Ң??째??퉪(?X???ב(ΡU?V?Oޔ\ :i w??֢ǍTf։8Z5a?Й?&#240;???Y?Ǖ^ȽXղ?]gڣ=ţ]?=k??Eԟ޴?X\뒥?/S\?ߺ????????認?@???@ο޴߽?94?5???W n?u膎FȭVtn??:=BT?|ո??ﳋ?HwGO?K\?TЫݎ)jtVzꑑ?-ڷ��??֥=遁aԔ????Z((????Z(??(??((???RҐQA?Ȥ挒dRdSsJ))€KEQE???(??(??(??(??(??(??@RQ@ E&h?4???? -2?(ˋs???Qŀ%&ii(sFi??਍%???sŒֽhi?A??=?d?5[ɶ?%힍sڵ?f+ᏬV???Ȏ9?%? Q?Y?fϵh?#?,??A뚖Ы?ɖo~??ٴȉߧ'ޫ??)!"P???X.swd螢禅dݘʥ|?죈啁?Zp??ڂQ?|???Li?ެ???ѭ??(ۛ1?ؽ??,ֈbN???:+v?dx?9??R?졽Ş?t?H?)?0|?=j?y 3?i??o-w NijO?��ٕ��œҳ煏?&?Gcaxٳ??"??S?~?h????0??ǿI㱪֞&գ s:?>tͣކ?䤢?Gw?ۼО wTK;ؼJ㟩?ڏpq???֠ם?f{??[IJ"?織֦?E?"?#?'&??^竭ܫэ)???W?EuцOC[y???FrMhXk?��IJi?????J."A%/?Pґp, )Š??7E&#165;?2?̪?͞e;?咴ݕ?}??ͼ>i܅?Ի?@?}p޴5???ፍԨxcUCS?Q??dN?ը???Ը!?3??R?O╭nU?א???"?ǩJ?f?&#240;??;"??m[<W?nwT?дf?ዐk?2jhG-F?ЖȢ??????-@Ӣ??��??Ν…ڳYǐ?????:*?^?t50?OZ.;)????^"??J]M᨜F??��׺?nՃp縍R????ߨ䣷??��?̧ ?|?̵˲??H'_Z八?O???O#2:v?U??ڌjq?W9%��4?OSM@\ǡ꿆?+ #?q܈?a?jA??q?␓L鷊O1k?}X?k8?̮??̔?ų?ی*Eղ94?&#168;跊3XQjꍂjؔSxQ??ȵ?y5h׸??WB>?k#֌?ĭ]?c֍CCf????GZp?Cދ?Ŋ*??S????j8zԂ@h ??–??ъuܒ?Z(ʛ?࿕ҷ_?f?̓4?ӳK???Ҧ???4ݔ??\՛wً،qU)%????6?L?.斥?فv?*՝Ӻn?c? V??6盞*ɁU!P?~r*??^\?ɫ??νؘ???#>d??⏼?? b2փ&袄c???O?Ȃ* ???*ᗝ2OsQ\Hc?aْy??Gَ4? ?A$?��?)?? ?ڼ뚄g??d3rqЕF?{퍁l��Ҵ��Bjx㘗 L?ʫ?ƿ붶z?R&#191;?g"؃숭1Jvs׾??ən#oP??쮣??|4?E٤?????bS ?��??H tś?RW)M?????쭛�zב?ݛ˵????իZ[?nh#'ר?U3??x?ٜr?2???fc?R??M1Ψ?K???B)7Q??섓M.ሩ?3Q?R?⢤暁ܓ?Ғf?f?4Ŭ?p5 ?2c?\dSXS?lji???1"?s@;?4?Wu?~{һ?&#208;x5'ژq??????s֜'8땷Sԑq?㫇?}MBR晷ڤ^?i?y)ꆢš\ ̟޴﹏$??Rd?\ ҮT膦?ػՄ????p.?쌹j?ΏSP碣lզ&Zg?<??A????)w ?f攋?S7TZO6?Ω3P h��?ϽV��C-n???%?Ɉ KRn5?K擂M䒹ϓ&???=,n'?>?qK?P;n>? ��??"ڝȣԙΣT&#211;?R? M$Ԥ?H5=뫽(z\?w5גzĂage crop successful
    Same using:

    PHP Code:
    header('content-type: image/jpeg');  

    $watermark imagecreatefrompng('watermark.png');  
    $watermark_width imagesx($watermark);  
    $watermark_height imagesy($watermark);  
    $image imagecreatetruecolor($watermark_width$watermark_height);  
    $image imagecreatefromjpeg($images_dir."/".$filename);  
    $size getimagesize($images_dir."/".$filename);  
    $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); 

    Cheers

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you please give your whole/complete code so that i could see again and correct if anything??
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •