Filesize of jpeg.Encode

polaris · · 719 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey gophers,</p> <p>I&#39;ve written quickly a tiny app for mocking media structures for your dev env. </p> <p>Works so far so good but I&#39;ve noticed that the output JPG images have a pretty huge file size despite I&#39;ve set the quality for JPEG encoding to 1.</p> <p>Source: <a href="https://github.com/SchumacherFM/mediamock/blob/master/csv.go#L80" rel="nofollow">https://github.com/SchumacherFM/mediamock/blob/master/csv.go#L80</a></p> <p>The code mocks e.g. an image 7456 × 5184 pixels, containing only one color, and results in a file size of 605kb. If I pass the image file to <a href="https://imageoptim.com/" rel="nofollow">https://imageoptim.com/</a> the filesize drops to 114kb.</p> <p>Is there any chance to achieve an nearly equal file size of 114kb with Go?</p> <p>Thx!</p> <hr/>**评论:**<br/><br/>dtfinch: <pre><p>I think the problem is that Go&#39;s <a href="https://golang.org/src/image/jpeg/writer.go" rel="nofollow">encoder</a> uses a pregenerated huffman table (allowing single-pass encoding), instead of doing another pass to construct an optimal table. Fine for everyday photos, but not for more highly compressible images. I think you just need to us another encoder.</p> <blockquote> <p>// This encoder uses the same Huffman encoding for all images.</p> </blockquote></pre>schumacherfm: <pre><p>Ok, I thought so ... currently not in the mood to rewrite the encoder 8-) Thanks!</p></pre>hayzeus: <pre><p>You could just spawn off imagemagick if you want some flexibility. There are also go bindings, but I think that gets you into cgo</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

719 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传