是这样不??
保存为ansi编码的bat- @set @l_l=1;/*&echo off
- rem #!bin/bash # -*- coding:ASCII-8BIT -*-
-
- rem 透明度 0-1
- set touming=0.7
-
- rem 水印图
- set shuiyin="1比1的水印.png"
-
- cmd /u /c dir /b *jpg *png *bmp| cscript //u //e:jscript //nologo "%~f0" "%shuiyin:\=\\%" "%touming%"
- pause&exit /b 0 */
-
- if (!WScript.Arguments.Length){WScript.Quit();}
- var f=[],l='';
- while (!WScript.StdIn.AtEndOfStream) {
- l=WScript.StdIn.ReadLine();
- f.push(l);
- }
-
- function Sprite(){
- this.bitmap=GetObject('new:WIA.ImageFile');
- this.shuiyin=GetObject('new:WIA.ImageFile');
- this.filter=GetObject('new:WIA.ImageProcess');
- this.filter.Filters.Add(this.filter.FilterInfos("ARGB").FilterID);
- this.filter.Filters.Add(this.filter.FilterInfos("Convert").FilterID);
- this.filter_argb=function(x){this.filter.Filters(1).Properties("ARGBData")=x;}
- this.filter_format=function(x){this.filter.Filters(2).Properties("FormatID").Value=x;}
- this.toumingdu=parseFloat(WScript.Arguments(1));
- this.save_to_file=function(x,y,z){
- if(z)this.filter_format(z);
- if(x){
- this.filter_argb(x);
- var new_bitmap=this.filter.Apply(this.bitmap);
- new_bitmap.SaveFile(y);
- }}
- }
-
- var file=GetObject("new:scripting.filesystemobject");
- var sprite=new Sprite();
- var t=sprite.toumingdu?1-sprite.toumingdu:1;
- sprite.filter_format("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"); //jpeg
- sprite.shuiyin.LoadFile(WScript.Arguments(0));
- var d=sprite.shuiyin.ARGBData;
-
- for(var i=0;i<f.length;i++){
- if(f[i]==WScript.Arguments(0))continue;
- sprite.bitmap.LoadFile(f[i]);
- WScript.Echo("正在处理文件: "+f[i]);
- var d2=sprite.bitmap.ARGBData;
- var x=sprite.shuiyin.Width;
- var y=sprite.shuiyin.Height;
- var x2=sprite.bitmap.Width;
- var y2=sprite.bitmap.Height;
- var cx,cx2,cw,cw2,ch,ch2;
- if(x<x2){
- cx=1;cw=x;
- cx2=Math.floor((x2-x)/2);cw2=x2;
- }else{
- cx=Math.floor((x-x2)/2);cw=x;
- cx2=1;cw2=x2;
- }
- if(y<y2){
- cy=1;ch=y;
- cy2=Math.floor((y2-y)/2);ch2=y2;
- }else{
- cy=Math.floor((y-y2)/2);ch=y;
- cy2=1;ch2=y2;
- }
- cx=cx?cx:1;cy=cy?cy:1;
- cx2=cx2?cx2:1;cy2=cy2?cy2:1;
- WScript.Echo("w:",x,"x",y,"\ns:",x2,"x",y2);
- WScript.Echo("p:",cx,cy,cw,ch,"=>",cx2,cy2,cw2,ch2);
- for(;(cy<=ch)&&(cy2<=ch2);cy++,cy2++){
- var ccx=cx,ccx2=cx2;
- for(;(cx<=cw)&&(cx2<=cw2);cx++,cx2++){
- var v=d((cy-1)*cw+cx);
- var v2=d2((cy2-1)*cw2+cx2);
- var a=(v&0xff000000)>>>24;
- if(!a)continue;
- var r=(v&0x00ff0000)>>>16;
- var g=(v&0x0000ff00)>>>8;
- var b=v&0x000000ff;
- var b2=v2&0x000000ff;
- var g2=(v2&0x0000ff00)>>>8;
- var r2=(v2&0x00ff0000)>>>16;
- var a2=(v2&0xff000000)>>>24;
- r2=t*r+(1-t)*r2;
- g2=t*g+(1-t)*g2;
- b2=t*b+(1-t)*b2;
- r2=Math.floor(r2*r2/255);
- g2=Math.floor(g2*g2/255);
- b2=Math.floor(b2*b2/255);
- v2=(a2<<24)|(r2<<16)|(g2<<8)|b2;
- d2((cy2-1)*cw2+cx2)=v2;
- }
- cx=ccx;cx2=ccx2;
- }
- var nnn=0;new_filename="加了水印的_"+f[i]+".jpg";
- while(file.FileExists(new_filename)){
- nnn+=1;
- new_filename="加了水印的_"+f[i]+"("+nnn+")"+".jpg";
- }
- WScript.Echo("处理完成\n保存到文件: ",new_filename);
- sprite.save_to_file(d2,new_filename);
- WScript.Echo("保存完成\n");
- }
- WScript.Quit();
复制代码
|