user-pic

[求助]路扬请进。。。。。。

Vote 0 Votes

我的图片水印一修改如下图 ↓
http://easun.org/upload/early/1_1128508048.jpg
但,如何能象下图那样给水印加上背景框?
http://easun.org/upload/early/2_1128508068.jpg

我看见attachment.cgi里有一句 my $background 是不是跟这个有关系?
应该怎样修改?

另:是不是只能给 jpg  jpeg  png 格式的图片加水印?

7 Replies

| Add a Reply
  • 我的代码 ↓

       if ($picwater eq "yes" && ($fileext eq 'jpg' || $fileext eq 'jpeg' || $fileext eq 'png')) {
    $filesize = (stat("$file"))Ε];
    $fileext = 'jpeg' if ($fileext eq 'jpg');
    print header(-type=>"image/$fileext", -attachment=>$filename, -expires=>'-1d', -content_length=>$filesize);

    if ($fileext eq "jpeg") {
         $image = GD::Image->newFromJpeg($file, 1);
    } else {
         $image = GD::Image->newFromPng($file, 1);
     }

    $watername = "http://longyv.vicp.net/" if ($watername eq "");

    my ($imwidth, $imheight) = $image->getBounds ();

    my $font = GD::gdLargeFont();
    my $fontwidth = $font->width * length $watername;

    my $background = $image->colorAllocate(0,0,0);
    my $txt1 = $image->colorAllocate(255,255,255);
    my $txt2 = $image->colorAllocate(0,0,0);

    if ($imheight > 40 && $imwidth > 200) {  # 小于 200*40 的图片不加水印
       if ($picwaterplace1 eq "yes") { # 左上角
           $image->string($font, 8, 9, $watername, $txt2);
           $image->string($font, 8, 10, $watername, $txt2);
           $image->string($font, 8, 11, $watername, $txt2);
           $image->string($font, 9, 9, $watername, $txt2);
           $image->string($font, 9, 11, $watername, $txt2);
           $image->string($font, 10, 9, $watername, $txt2);
           $image->string($font, 10, 10, $watername, $txt2);
           $image->string($font, 10, 11, $watername, $txt2);
           $image->string($font, 9, 10, $watername, $txt1);
       }
       if ($picwaterplace2 eq "yes") { # 左下角
           $image->string($font, 8, $imheight - 31, $watername, $txt2);
           $image->string($font, 8, $imheight - 30, $watername, $txt2);
           $image->string($font, 8, $imheight - 29, $watername, $txt2);
           $image->string($font, 9, $imheight - 31, $watername, $txt2);
           $image->string($font, 9, $imheight - 29, $watername, $txt2);
           $image->string($font, 10, $imheight - 31, $watername, $txt2);
           $image->string($font, 10, $imheight - 30, $watername, $txt2);
           $image->string($font, 10, $imheight - 29, $watername, $txt2);
           $image->string($font, 9, $imheight - 30, $watername, $txt1);
       }
       if ($picwaterplace3 eq "yes") { # 右上角
           $image->string($font, $imwidth - $fontwidth - 8, 9, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, 10, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, 11, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, 9, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, 11, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, 9, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, 10, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, 11, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, 10, $watername, $txt1);
       }
       if ($picwaterplace4 eq "yes") { # 右下角
           $image->string($font, $imwidth - $fontwidth - 8, $imheight - 31, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, $imheight - 30, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, $imheight - 29, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, $imheight - 31, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, $imheight - 29, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, $imheight - 31, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, $imheight - 30, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, $imheight - 29, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, $imheight - 30, $watername, $txt1);
       }
    }
    binmode(STDOUT);
    if ($fileext eq "jpeg") {
       print $image->jpeg;
    } else {
       print $image->png;
    }
    exit;
       }

    if ($pvtdown ne "no") {
    $BOF = 0;
    $EOF = (-s $file);
    $fileext = 'jpeg' if ($fileext eq 'jpg');
    $fileext = 'html' if ($fileext eq 'htm');
    $fileext = 'plain' if ($fileext eq 'txt');
    if ($fileext =~ /^(gif|jpeg|png|bmp)$/) {
       $fileext = "image/$fileext";
       $fileadd = "";
    } elsif ($fileext eq 'swf') {
       $fileext = "application/x-shockwave-flash";
       $fileadd = "";
    } elsif ($fileext =~ /^(plain|html)$/) {
       $fileext = "text/$fileext";
       $fileadd = "";
    } else {
       $fileext = "attachment/$fileext";
       $fileadd = " attachment;";
    }
     
    $HTTP_RANGE = $ENV{HTTP_RANGE};
    if ($HTTP_RANGE ne '' && $HTTP_RANGE =~ /^bytes=(Ύ-9]+)\-(Ύ-9]+)$/ && $1 > -1 && $1 < $2 && $2 <= $EOF) {
       ($BOF, $EOF) = ($1, $2);
       print "HTTP/1.1 206 Partial Content\n";
       print "Accept-Ranges: bytes\n";
       print "Content-Range: bytes $BOF-$EOF/" . ($EOF + 1) . "\n";
       $EOF++;
    }
    $filesize = $EOF - $BOF;
    print "Accept-Ranges: bytes\n";
    print "Content-Length: $filesize\n";
    print "Content-Disposition:$fileadd filename=$filename\n";
    print "Content-Type: $fileext\n\n";
    binmode (STDOUT);
    print &readattachment ($file, $BOF, $EOF);
    exit;
    } else {
       print header(-charset=>gb2312,-location=>$file2,-expires=>now,-cache=>yes);
       exit;
    }
    exit;

  • 背景颜色

    my $background = $image->colorAllocate(0,0,0);

    这句控制。。直接改就好了。

  • my $background = $image->colorAllocate(51,204,51);
    改了没反应撒~!


  • 嘿嘿~!胡乱改地!管用列~!


    my $lyblack = $image->colorAllocate(204,204,204);
    my $background = $image->colorAllocate(255,0,0);
    my $txt1 = $image->colorAllocate(255,255,255);
    my $txt2 = $image->colorAllocate(0,0,0);

    if ($imheight > 40 && $imwidth > 200) {  # 小于 200*40 的图片不加水印
       if ($picwaterplace1 eq "yes") { # 左上角
           $image->rectangle(7,9,186,28,$lyblack);
           $image->fillToBorder(58,15,$lyblack,$background);
           $image->string($font, 8, 9, $watername, $txt2);
           $image->string($font, 8, 10, $watername, $txt2);
           $image->string($font, 8, 11, $watername, $txt2);
           $image->string($font, 9, 9, $watername, $txt2);
           $image->string($font, 9, 11, $watername, $txt2);
           $image->string($font, 10, 9, $watername, $txt2);
           $image->string($font, 10, 10, $watername, $txt2);
           $image->string($font, 10, 11, $watername, $txt2);
           $image->string($font, 9, 10, $watername, $txt1);
       }
       if ($picwaterplace2 eq "yes") { # 左下角
           $image->rectangle(7,$imheight - 31,186,$imheight - 12,$lyblack);
           $image->fillToBorder(58,$imheight - 15,$lyblack,$background);
           $image->string($font, 8, $imheight - 31, $watername, $txt2);
           $image->string($font, 8, $imheight - 30, $watername, $txt2);
           $image->string($font, 8, $imheight - 29, $watername, $txt2);
           $image->string($font, 9, $imheight - 31, $watername, $txt2);
           $image->string($font, 9, $imheight - 29, $watername, $txt2);
           $image->string($font, 10, $imheight - 31, $watername, $txt2);
           $image->string($font, 10, $imheight - 30, $watername, $txt2);
           $image->string($font, 10, $imheight - 29, $watername, $txt2);
           $image->string($font, 9, $imheight - 30, $watername, $txt1);
       }
       if ($picwaterplace3 eq "yes") { # 右上角
           $image->rectangle($imwidth - 187,9,$imwidth - 8,28,$lyblack);
           $image->fillToBorder($imwidth - 58,15,$lyblack,$background);
           $image->string($font, $imwidth - $fontwidth - 8, 9, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, 10, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, 11, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, 9, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, 11, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, 9, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, 10, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, 11, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, 10, $watername, $txt1);
       }
       if ($picwaterplace4 eq "yes") { # 右下角
           $image->rectangle($imwidth - 8,$imheight - 31,$imwidth - 187,$imheight - 12,$lyblack);
           $image->fillToBorder($imwidth - 58,$imheight - 15,$lyblack,$background);
           $image->string($font, $imwidth - $fontwidth - 8, $imheight - 31, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, $imheight - 30, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 8, $imheight - 29, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, $imheight - 31, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, $imheight - 29, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, $imheight - 31, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, $imheight - 30, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 10, $imheight - 29, $watername, $txt2);
           $image->string($font, $imwidth - $fontwidth - 9, $imheight - 30, $watername, $txt1);
       }
    }

  • 对了,哪个颜色估计是定义成了透明色。。
    所以不行。


    这个和Leohacks的不同,Leohacks用的是图片叠加,而这个是直接写字。。

  • 请问怎么设置背景色和边框,字符的通明度?

    及怎样调入字体?

    GD图形库的一些参数能不能给个列表?

    我自己画的汉字 ↓
    http://easun.org/upload/early/vvv_1128804841_1129021178.jpg

  • GD支持中文要求很高。
    看看这里

    http://search.cpan.org/~lds/GD-2.28/GD.pm

    GD的作用不只是这点,用法太复杂了。自己慢慢研究吧。就是上面的地址。

Add a Reply

Forum Groups

Good Perl Books

Perl 學習手札

作者:簡信昌

Perl 學習手札 , 一本优秀的中文Perl在线学习资料。

Perl 程序讨论区

12 50

Last Topic: [注意]本区文章归档区 by 路杨 on Oct 16, 2006

事物处理及其他

113 1410

Last Topic: 踩个脚印 by 眼睛oo on Dec 4, 2010

测试私密区

测试私密区

18 88

Notice: 用于测试程序或者不可告人之秘密。不要问我要密码哦。。[此为原LB_ES论坛系统保留项,只限原有权限朋友进入,不再接受注册]

OpenID accepted here Learn more about OpenID