zoukankan      html  css  js  c++  java
  • Html转成Image

    html转图片,原来用了html2image.jar,但是做不到复杂的css js渲染效果。

    在网友推荐下,可以用wkhtmltoimage插件,这是用谷歌浏览器的内核webkit,网上搜一下可以下载,同时也是可以wkhtmltopdf,在同一个安装包内。

    如果需要参数设置,在cmd中打一下 wkhtmltoimage /?

    以下的代码我是用作手机版本的

    /**
    	 * 生成图片
    	 * @param nickname 微信昵称
    	 * @param headurl  微信
    	 */
    	public static void CreateImage(String nickname,String headurl,String openId){
    		try {
    			
    		    String plugpath="C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage";
    			
    			String montherUrl="http://localhost/mother/index.html";
    			montherUrl=montherUrl+"?nickname="+nickname+"&headurl="+headurl+"";
    			
    			System.out.println(montherUrl);
    			
    			String imgpath="e:\"+openId+".jpg";
    			
    			ProcessBuilder pb = new ProcessBuilder(plugpath,"--crop-h","1136","--crop-w","640",montherUrl,imgpath );
    			Process process;
    			process = pb.start();
    		
    			//注意,调用process.getErrorStream()而不是process.getInputStream()
    			BufferedReader errStreamReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); 
    			System.out.println("read errstreamreader");
    			String line = null;
    			line = errStreamReader.readLine(); 
    			while(line != null) { 
    			    //System.out.println(line); 
    			    line = errStreamReader.readLine(); 
    			}
    			process.destroy();
    		    System.out.println("destroyed process");
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    

      

  • 相关阅读:
    ES集群性能调优链接汇总
    【转】dmesg 时间转换
    广师大笔记汉诺塔
    广师大python学习笔记求派的值
    155. 最小栈(c++)
    160. 相交链表(c++)
    论文 数据集总结
    论文阅读 总结 复习
    121. 买卖股票的最佳时机(c++)
    9. 回文数(c++)
  • 原文地址:https://www.cnblogs.com/Anders888/p/6836796.html
Copyright © 2011-2022 走看看