去除Visual Paradigm输出图片中的浮水印

来源:互联网 发布:内涵段子网站源码 编辑:程序博客网 时间:2024/05/19 03:42

BoUML都收费了,argoUML半年没更新了,而startUML六年多没更新了,免费的UML工具里就数VP的社区版还不错了。唯一的缺憾就是输出图片有浮水印,虽说咱们也四处宣传VP,但输出的图片实在不方便。VP 9已经将浮水印贴满整个背景,影响导出图片的可读性。

 

不过,SVG导出功能还在!(这是我唯一还在坚持VP的理由!) 我写了一段脚本,帮助去除VP输出SVG图片中的浮水印,并转成PNG。这个PNG转换的功能依赖于Inkscape,没有的话去SourceForge.net下吧。 注意安装后要把Inkscape的安装路径放在PATH中去。

Inkscape支持命令行,如下:

  inkscape -f srcSVGFile -e tgtPNGFile -d 150  (d后面的dpi值,150基本可以适用于放到PPT讲解用了. 其它参数用--help就可以看了)

 

脚本也简单,就是把SVG文件的某个特定的浮水印字符去除,然后呼叫inkscape转换下就可以了。支持单个文件转换或者一个目录下所有文件转换,还算方便吧。

#!/usr/bin/python# coding: utf-8#/*!#@brief Description#  A simple utility to remove watermark for SVG files exported by VP 9.0 ~ VP 12.x#*/import os,sys,string,datetime,copy,resrcSVGString = ["Visual Paradigm for UML Enterprise Edition [evaluation copy]","Visual Paradigm for UML Community Edition [not for commercial use]","Visual Paradigm for UML Modeler Edition [evaluation copy]"]pathInkSpace = "/Applications/Inkscape.app/Contents/Resources/bin/inkscape"def replaceStringInNewFile(srcFile):file=open(srcFile, "r") if None==file:print "Could not open for %s updating" %srcFilereturn -1allLines=file.readlines()file.close()index = 0for eachLine in allLines:for srcString in srcSVGString:if 0<=string.find(eachLine,srcString):allLines[index] = eachLine.replace(srcString,' ')breakindex = index+1file = open(srcFile,"w")file.writelines(allLines)file.close()return 0def convertSVGToPNG(filename):fileStr, extStr = os.path.splitext(filename)if 0 == replaceStringInNewFile(filename):convertCmd=pathInkSpace+" -f\""+filename+"\" -e \""+fileStr+".png\" -d 150";return os.system(convertCmd)else:return -1def convertAllSVNInFolder(srcFolder):if not os.path.isdir( srcFolder ):return -1paths = os.listdir( srcFolder )for path in paths:filePath = os.path.join( srcFolder, path )if filePath[-4:].lower() == ".svg":convertSVGToPNG(filePath)return 0# Main entryif __name__ =="__main__":print 'Please ensure the Inkscape has been installed,'print ' and put the installed folder in the PATH!' if len(sys.argv) < 2:print '\tUsage: 'print '\t python svgconvert.py sourceSVGFile or'print '\t python svgconvert.py svnFolder'print ' 'elif os.path.isdir(sys.argv[1]):convertAllSVNInFolder(sys.argv[1])else:convertSVGToPNG(sys.argv[1])print '\nFinished! Enjoy the conversation result! 'print 'If you have any comment, pls mail to'print '\t horky.chen@gmail.com'print ''


原创粉丝点击