使用svgo压缩图片

要先安装nodejs和svgo 

安装好nodejs后在cmd里面输入npm i svgo -g(liunx下直接输入)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2020/3/2.
 */
public class TestTT {

    public static void main(String[] args) throws IOException, InterruptedException {
        String command = "cmd /c svgo d:/dwg/a.svg"; //windows
//        String command = " svgo /home/a.svg";//linux
//        String command = "ping baidu.com -t";
//        String command = "cmd /c node -v";
        Process process = Runtime.getRuntime().exec(command);
        BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        process.waitFor();
        System.out.println ("exit: " + process.exitValue());
        process.destroy();
    }
}

  

posted on 2020-03-03 10:17  james-roger  阅读(638)  评论(0编辑  收藏  举报