发新话题
打印

[LeoBBS] 增加图片水印效果教程

增加图片水印效果教程

教程版权:三元社区 - 阿强
适用版本:LeoBBS X 系列
修改文件:setstyles.cgi、attachment.cgi
教程作用:增加图片水印功能
效果参考: http://www.lzeweb.com/cgi-bin/city/topic.cgi?forum=33&topic=946 http://www.lzeweb.com/cgi-bin/city/photo.cgi?action=pic&id=1124808566.jpg_4
一、打开 setstyles.cgi,找到:
复制内容到剪贴板
代码:
                <tr>
                <td bgcolor=&#35;FFFFFF colspan=2>
                <font color=&#35;333333>上传的 JPG 图片上水印的文字<BR>注:<font color=red>不能用中文</font>,也不要过长,否则影响效果</font><BR><BR></td>
                <td bgcolor=&#35;FFFFFF>
                <input type=text name="watername" value="&#36;watername" size=30></td>
                </tr>
在它上面加上:
复制内容到剪贴板
代码:
<!-- 3plugs 水印图片 -->
                <tr>
                <td bgcolor=&#35;FFFFFF colspan=2>
                <font color=&#35;333333>图片水印名称<BR>注:水印图必须为 PNG 格式,如果留空则使用文字水印<BR><BR></td>
                <td bgcolor=&#35;FFFFFF>
                <input type=text name="waterpic" value="&#36;waterpic" size=20> 例: waterlogo.png,图片保存在 &#36;imagesurl 路径</td>
                </tr>
<!-- end -->
二、打开 attachment.cgi,找到:
复制内容到剪贴板
代码:
&#36;watername = "http://bbs.leobbs.com/" if (&#36;watername eq "");
my (&#36;imwidth, &#36;imheight) = &#36;image->getBounds ();
my &#36;font = GD::gdLargeFont();
my &#36;fontwidth = &#36;font->width * length &#36;watername;
my &#36;background = &#36;image->colorAllocate(0,0,0);
my &#36;txt1 = &#36;image->colorAllocate(255,255,255);
my &#36;txt2 = &#36;image->colorAllocate(0,0,0);
if (&#36;imheight > 40 && &#36;imwidth > 200) {  &#35; 小于 200*40 的图片不加水印
    if (&#36;picwaterplace1 eq "yes") { &#35; 左上角
        &#36;image->string(&#36;font, 10, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 11, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 9, 10, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, 10, 10, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace2 eq "yes") { &#35; 左下角
        &#36;image->string(&#36;font, 10, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 11, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 9, &#36;imheight - 20, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, 10, &#36;imheight - 20, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace3 eq "yes") { &#35; 右上角
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9 + 1, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10 + 1, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9, 10, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10, 10, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace4 eq "yes") { &#35; 右下角
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9 + 1, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10 + 1, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9, &#36;imheight - 20, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10, &#36;imheight - 20, &#36;watername, &#36;txt1);
    }
}
修改为:
复制内容到剪贴板
代码:
      if(&#36;waterpic eq "") {
&#36;watername = "http://bbs.leobbs.com/" if (&#36;watername eq "");
my (&#36;imwidth, &#36;imheight) = &#36;image->getBounds ();
my &#36;font = GD::gdLargeFont();
my &#36;fontwidth = &#36;font->width * length &#36;watername;
my &#36;background = &#36;image->colorAllocate(0,0,0);
my &#36;txt1 = &#36;image->colorAllocate(255,255,255);
my &#36;txt2 = &#36;image->colorAllocate(0,0,0);
if (&#36;imheight > 40 && &#36;imwidth > 200) {  &#35; 小于 200*40 的图片不加水印
    if (&#36;picwaterplace1 eq "yes") { &#35; 左上角
        &#36;image->string(&#36;font, 10, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 11, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 9, 10, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, 10, 10, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace2 eq "yes") { &#35; 左下角
        &#36;image->string(&#36;font, 10, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 11, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, 9, &#36;imheight - 20, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, 10, &#36;imheight - 20, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace3 eq "yes") { &#35; 右上角
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9 + 1, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10 + 1, 11, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9, 10, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10, 10, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace4 eq "yes") { &#35; 右下角
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9 + 1, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10 + 1, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9, &#36;imheight - 20, &#36;watername, &#36;txt1);
        &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10, &#36;imheight - 20, &#36;watername, &#36;txt1);
    }
}
      } else {
&#36;image1 = GD::Image->newFromPng("&#36;{imagesdir}&#36;waterpic", 1);
my (&#36;width,&#36;height) = &#36;image1->getBounds ();&#35; 得到水印logo图尺寸
&#36;image1->transparent (&#36;image1->colorAllocate (0,0,0));&#35; 得出黑色以及设logo的黑色为透明
my (&#36;imwidth, &#36;imheight) = &#36;image->getBounds ();&#35; 得到主图的尺寸
my (&#36;zwidth, &#36;zheight);
&#35; 如果主图宽大于logo宽2倍,高大于logo高2倍,则加水印
if (((int (&#36;imwidth / 2)) > &#36;width) && ((int (&#36;imheight / 2)) > &#36;height))
{
    if (&#36;picwaterplace1 eq ';yes'; || &#36;picwaterplace3 eq ';yes';)
    {
        &#36;zheight = 10;
    } else {
        &#36;zheight = int (&#36;imheight - &#36;height - 10);
    }
    if (&#36;picwaterplace1 eq ';yes'; || &#36;picwaterplace2 eq ';yes';)
    {
        &#36;zwidth = 10;
    } else {
        &#36;zwidth = int (&#36;imwidth - &#36;width - 10);
    }
    &#36;image->copy (&#36;image1, &#36;zwidth, &#36;zheight, 0, 0, &#36;width, &#36;height);
}
      }
三、完成。其它的加上传人名字、水印透明度等效果自行参考修改。
四、本站图片水印LOGO: http://www.lzeweb.com/city/waterlogo.png
动力来源于交流,只有交流你才不会陌生 [www.lzeweb.com www.524200.cn www.0759i.com www.e94.cn]
QEJBIPCDEFGH

TOP

增加图片水印效果教程

水印圖片的大小和上傳圖片的大小要在多少比例下才可以正常顯示水印圖片呢?
我在異靈版上面加入這個修改後,
試了幾個主題,
如果只是顯示文字水印可正常顯示文字浮水印,
可是設定了圖片浮水印後,
該上傳圖片卻變成了叉燒包無法顯在在主題內.
是否是異靈版內的代碼和官方有些不一樣的關係?
复制内容到剪贴板
代码:
    if (&#36;picwater eq "yes" && (&#36;fileext eq ';jpg'; || &#36;fileext eq ';jpeg'; || &#36;fileext eq ';png';)) {
&#36;filesize = (stat("&#36;file"))[7];
&#36;fileext = ';jpeg'; if (&#36;fileext eq ';jpg';);
    if (-e "&#36;file.waterpicture") {
&#36;BOF = 0;
&#36;EOF = (-s "&#36;file.waterpicture");
&#36;fileext = ';jpeg'; if (&#36;fileext eq ';jpg';);
  
&#36;HTTP_RANGE = &#36;ENV{HTTP_RANGE};
if (&#36;HTTP_RANGE ne ';'; && &#36;HTTP_RANGE =~ /^bytes=([0-9]+)\-([0-9]+)&#36;/ && &#36;1 > -1 && &#36;1 < &#36;2 && &#36;2 <= &#36;EOF) {
    (&#36;BOF, &#36;EOF) = (&#36;1, &#36;2);
    print "HTTP/1.1 206 Partial Content\n";
    print "Accept-Ranges: bytes\n";
    print "Content-Range: bytes &#36;BOF-&#36;EOF/" . (&#36;EOF + 1) . "\n";
    &#36;EOF++;
}
&#36;filesize = &#36;EOF - &#36;BOF;
print "Accept-Ranges: bytes\n";
print "Content-Length: &#36;filesize\n";
print "Content-Disposition:&#36;fileadd filename=&#36;filename\n";
print "Content-Type: &#36;fileext\n\n";
binmode (STDOUT);
print &readattachment ("&#36;file.waterpicture", &#36;BOF, &#36;EOF);
exit;
   }
print header(-type=>"image/&#36;fileext", -attachment=>&#36;filename, -expires=>';0';, -content_length=>&#36;filesize);
if (&#36;fileext eq "jpeg") {
      eval { &#36;image = GD::Image->newFromJpeg(&#36;file, 1); };
      &#36;image = GD::Image->newFromJpeg(&#36;file) if (&#36;@);
} else {
      eval { &#36;image = GD::Image->newFromPng(&#36;file, 1); };
      &#36;image = GD::Image->newFromPng(&#36;file) if (&#36;@);
  }
if(&#36;waterpic eq "") {
&#36;watername = "http://bbs.leobbs.com/" if (&#36;watername eq "");
my (&#36;imwidth, &#36;imheight) = &#36;image->getBounds ();
my &#36;font = GD::gdLargeFont();
my &#36;fontwidth = &#36;font->width * length &#36;watername;
my &#36;background = &#36;image->colorAllocate(0,0,0);
my &#36;txt1 = &#36;image->colorAllocate(255,255,255);
my &#36;txt2 = &#36;image->colorAllocate(0,0,0);
if (&#36;imheight > 40 && &#36;imwidth > 200) {  &#35; 小于 200*40 的圖片不加水印
    if (&#36;picwaterplace1 eq "yes") { &#35; 左上角
       &#36;image->string(&#36;font, 10, 11, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, 11, 11, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, 9, 10, &#36;watername, &#36;txt1);
       &#36;image->string(&#36;font, 10, 10, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace2 eq "yes") { &#35; 左下角
       &#36;image->string(&#36;font, 10, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, 11, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, 9, &#36;imheight - 20, &#36;watername, &#36;txt1);
       &#36;image->string(&#36;font, 10, &#36;imheight - 20, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace3 eq "yes") { &#35; 右上角
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9 + 1, 11, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10 + 1, 11, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9, 10, &#36;watername, &#36;txt1);
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10, 10, &#36;watername, &#36;txt1);
    }
    if (&#36;picwaterplace4 eq "yes") { &#35; 右下角
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9 + 1, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10 + 1, &#36;imheight - 20 + 1, &#36;watername, &#36;txt2);
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 9, &#36;imheight - 20, &#36;watername, &#36;txt1);
       &#36;image->string(&#36;font, &#36;imwidth - &#36;fontwidth - 10, &#36;imheight - 20, &#36;watername, &#36;txt1);
    }
}
    } else {
&#36;image1 = GD::Image->newFromPng("&#36;{imagesdir}&#36;waterpic", 1);
my (&#36;width,&#36;height) = &#36;image1->getBounds ();&#35; 得到水印logo圖尺寸
&#36;image1->transparent (&#36;image1->colorAllocate (0,0,0));&#35; 得出黑色以及設logo的黑色為透明
my (&#36;imwidth, &#36;imheight) = &#36;image->getBounds ();&#35; 得到主圖的尺寸
my (&#36;zwidth, &#36;zheight);
&#35; 如果主圖寬大于logo寬2倍,高大于logo高2倍,則加水印
if (((int (&#36;imwidth / 2)) > &#36;width) && ((int (&#36;imheight / 2)) > &#36;height))
{
    if (&#36;picwaterplace1 eq ';yes'; || &#36;picwaterplace3 eq ';yes';)
    {
       &#36;zheight = 10;
    } else {
       &#36;zheight = int (&#36;imheight - &#36;height - 10);
    }
    if (&#36;picwaterplace1 eq ';yes'; || &#36;picwaterplace2 eq ';yes';)
    {
       &#36;zwidth = 10;
    } else {
       &#36;zwidth = int (&#36;imwidth - &#36;width - 10);
    }
    &#36;image->copy (&#36;image1, &#36;zwidth, &#36;zheight, 0, 0, &#36;width, &#36;height);
}
     }
    open(FILEPIC, ">&#36;file.waterpicture");
    binmode(FILEPIC);
if (&#36;fileext eq "jpeg") {
    print FILEPIC &#36;image->jpeg;
} else {
    print FILEPIC &#36;image->png;
}
    close(FILEPIC);
binmode(STDOUT);
if (&#36;fileext eq "jpeg") {
    print &#36;image->jpeg;
} else {
    print &#36;image->png;
}
exit;
    }

TOP

增加图片水印效果教程

本教程是以官方原版修改的,正常通过。其它HACK版本不太清楚。
动力来源于交流,只有交流你才不会陌生 [www.lzeweb.com www.524200.cn www.0759i.com www.e94.cn]
QEJBIPCDEFGH

TOP

增加图片水印效果教程

强,强哥就是强

TOP

增加图片水印效果教程

强哥,发现一个问题,我使用的是七星的美化版,在这段代码上和官方版是没有什么区别的,图片水印也能加上去,但如果点击图片单独打开的话就没有水印了,这是怎么回事啊?但我看你这里是正常的。
另:该图片由XX上传,图片版权归原作者所有,这个水印怎么加

TOP

增加图片水印效果教程

第一个问题已经解决了,原来是复制代码的时候少了一句代码

TOP

增加图片水印效果教程

教程是没有问题的。呵
动力来源于交流,只有交流你才不会陌生 [www.lzeweb.com www.524200.cn www.0759i.com www.e94.cn]
QEJBIPCDEFGH

TOP

增加图片水印效果教程

另:该图片由XX上传,图片版权归原作者所有,这个水印怎么加

TOP

增加图片水印效果教程

我按照教程改了有问题,另外水印图片应该放在哪个具体目录下啊?我上传图片以后,帖子里显示的是图片链接失效。。。

TOP

增加图片水印效果教程

当我在管理中心把图片水印取消以后,原来不能显示的图片全都可以显示了。

TOP

增加图片水印效果教程

引用:
下面引用由一头老黄牛2006/03/21 10:07am 发表的内容:
我按照教程改了有问题,另外水印图片应该放在哪个具体目录下啊?我上传图片以后,帖子里显示的是图片链接失效。。。
水印图片放在你的non-cgi目录下,如果修改后出现链接失败,请仔细再检查一下。
动力来源于交流,只有交流你才不会陌生 [www.lzeweb.com www.524200.cn www.0759i.com www.e94.cn]
QEJBIPCDEFGH

TOP

增加图片水印效果教程

我的加上此代码后图片显示不了
是什么问题呢

TOP

增加图片水印效果教程

LeoBBS X 060331已经加入此功能。请去下载官方的新版。
动力来源于交流,只有交流你才不会陌生 [www.lzeweb.com www.524200.cn www.0759i.com www.e94.cn]
QEJBIPCDEFGH

TOP

增加图片水印效果教程

另:该图片由XX上传,图片版权归原作者所有,这个水印怎么加

TOP

增加图片水印效果教程

这个只提供在本站的商业区有。
动力来源于交流,只有交流你才不会陌生 [www.lzeweb.com www.524200.cn www.0759i.com www.e94.cn]
QEJBIPCDEFGH

TOP

发新话题
版块跳转