phantomjs输出文件大小:png v gif [英] phantomjs output file size: png v gif

查看:88
本文介绍了phantomjs输出文件大小:png v gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 phantomjs ,您可以选择用于

With phantomjs you can choose the file format to use for page.render().

我发现我为png获得的文件大小大约是我为gif获得的文件大小的三倍.我不知道png应该比gif更糟糕(就文件大小而言).实际上,我认为png会变得更好.

I'm finding that the file size I'm getting for png is around three times higher than what I'm getting for gif. I wasn't aware that png should be any worse (in terms of file size) than gif; in fact I thought png was meant to be better.

不幸的是,由于它支持可变的不透明度,我有点需要输出到png,但是更大的文件大小是个问题.

Unfortunately, I kinda need to output to png because of its support for variable opacity, but the larger file size is a bit of an issue.

那么,有什么方法可以控制png的文件大小?也许更改编码方案或其他?我目前正在使用phantomjs 1.9.8.

So, is there any way in which I can control file size of the png? Maybe change the encoding scheme or something? I'm currently using phantomjs 1.9.8.

推荐答案

在PhantomJS内

,无法减小png文件的大小,但是可以增大png文件的大小(只是为了娱乐):

Inside of PhantomJS

No, there is no way to make the png file size smaller, but there is a way to make it bigger (just for fun):

  1. 将文件渲染为png
  2. 将文件加载到适当大小的画布上,
  3. 以png或任何其他格式获取画布的Data-URI,
  4. 解码Base 64部分并写入文件(正确操作非常棘手).

PhantomJS 1.x存在一个错误,该错误会导致文件夸大但有效.

PhantomJS 1.x has a bug which results in a vastly inflated, but valid file.

只有jpeg渲染使您可以指定质量设置,这将导致文件更小,但是jpeg再次不支持透明性.

Only jpeg rendering enables you to specify a quality setting which will result in a smaller file size, but then again jpeg doesn't support transparency.

您还可以看到PhantomJS 2.0.0是否表现得更好,因为它下方的引擎比PhantomJS 1.x更新了近三年.

You could also see whether PhantomJS 2.0.0 behaves better, because it has an engine underneath it that is almost three years newer than in PhantomJS 1.x.

您最好的选择是按原样呈现PhantomJS中的png并使用您喜欢的库对其进行后处理.甚至可以打开它并再次保存.

Your best bet would be to render the png in PhantomJS as-is and post-process it with your favorite library. It may even be enough to open it and save it again.

例如,您可以使用子进程模块调用已安装的程序,或者可以打开包含此类服务的网页,然后上载捕获的文件或该文件的base64表示形式.可能性是无限的.

You can for example call an installed program with the child process module or your can open a webpage that contains such a service and upload the captured file or base64 representation of it. The possibilities are endless.

这篇关于phantomjs输出文件大小:png v gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆