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

简介: BoUML都收费了,argoUML半年没更新了,而startUML六年多没更新了,免费的UML工具里就数VP的社区版还不错了。唯一的缺憾就是输出图片有浮水印,虽说咱们也四处宣传VP,但输出的图片实在不方便。

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,re

srcSVGString = ["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" %srcFile
		return -1
	
	allLines=file.readlines()
	file.close()
	index = 0
	
	
	for eachLine in allLines:
		
		for srcString in srcSVGString:
			if 0<=string.find(eachLine,srcString):
				allLines[index] = eachLine.replace(srcString,' ')
				break
		
		index = index+1
		
		
	file = open(srcFile,"w")
	file.writelines(allLines)
	file.close()
	
	return 0

def 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 -1
			
			
def convertAllSVNInFolder(srcFolder):
	if not os.path.isdir( srcFolder ):
		return -1
	
	paths = os.listdir( srcFolder )
	for path in paths:
		filePath = os.path.join( srcFolder, path )
		if filePath[-4:].lower() == ".svg":
			convertSVGToPNG(filePath)
	
	return 0
	
# Main entry		
if __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 ''


目录
相关文章
|
人工智能 算法 自动驾驶
使用OpenCV实现Halcon算法(2)形状匹配开源项目,shape_based_matching
使用OpenCV实现Halcon算法(2)形状匹配开源项目,shape_based_matching
3422 0
使用OpenCV实现Halcon算法(2)形状匹配开源项目,shape_based_matching
|
7月前
|
区块链
EasyX趣味化编程note6,图片操作及文字
EasyX趣味化编程note6,图片操作及文字
66 0
【Word】docx转doc后公式转换为图片不清晰/模糊
【Word】docx转doc后公式转换为图片不清晰/模糊
338 0
【Word】获取SCI文献中高清EMF格式图片的方法
【Word】获取SCI文献中高清EMF格式图片的方法
127 0
|
测试技术
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
106 0
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
|
Web App开发 移动开发 前端开发
巧用 display: contents 增强页面语义
巧用 display: contents 增强页面语义
350 1
|
人工智能
PAT (Basic Level) Practice (中文)- 1049 数列的片段和(20 分)
PAT (Basic Level) Practice (中文)- 1049 数列的片段和(20 分)
81 0
|
前端开发 JavaScript 程序员
Visual Studio Code一个帮助我们进行括号配对的扩展应用,Rainbow
Visual Studio Code一个帮助我们进行括号配对的扩展应用,Rainbow
126 0
Visual Studio Code一个帮助我们进行括号配对的扩展应用,Rainbow
SAP Spartacus 如何调试待翻译文本的 place holder 和翻译之后的值
SAP Spartacus 如何调试待翻译文本的 place holder 和翻译之后的值
SAP Spartacus 如何调试待翻译文本的 place holder 和翻译之后的值
介绍一个快速找出 Visual Studio Code 代码多余空格的扩展 - trailing space
介绍一个快速找出 Visual Studio Code 代码多余空格的扩展 - trailing space
258 0
介绍一个快速找出 Visual Studio Code 代码多余空格的扩展 - trailing space