IMGKit icon indicating copy to clipboard operation
IMGKit copied to clipboard

Generated file much bigger than needed

Open ryana opened this issue 9 years ago • 0 comments

Hey there,

This is more of a question than an issue, but I couldn't find a Google Group-ish forum to ask questions.

I just generated this file:

2.1.2 :003 > File.open('test.png', 'wb+') {|f| f.write IMGKit.new('<html><body><ul><li>hi</li></ul></body></html').to_png }

The resulting image looked perfect, but it was huge. I ran in through convert with no options and:

ra:app(master) ryan$ ll test.png 
-rw-r--r--@ 1 ryan  staff  176553 Oct 24 09:24 test.png
ra:app(master) ryan$ convert test.png test-c.png
ra:app(master) ryan$ ll test*
-rw-r--r--  1 ryan  staff     733 Oct 24 09:29 test-c.png
-rw-r--r--@ 1 ryan  staff  176553 Oct 24 09:24 test.png
ra:app(master) ryan$ 

The "compressed" image is the same resolution and looks perfect. file tells me this:

ra:app(master) ryan$ file test.png 
test.png: PNG image data, 1024 x 43, 8-bit/color RGBA, non-interlaced
ra:app(master) ryan$ file test-c.png 
test-c.png: PNG image data, 1024 x 43, 8-bit colormap, non-interlaced
ra:app(master) ryan$ 

I ran a more complex image (a screenshot of Ramen) and got similar results:

ra:app(master) ryan$ ll ramen.png 
-rw-r--r--  1 ryan  staff  20468984 Oct 24 09:32 ramen.png
ra:app(master) ryan$ convert ramen.png ramen-c.png
ra:app(master) ryan$ ll ramen*
-rw-r--r--  1 ryan  staff    565074 Oct 24 09:32 ramen-c.png
-rw-r--r--  1 ryan  staff  20468984 Oct 24 09:32 ramen.png
ra:app(master) ryan$ file ramen.png 
ramen.png: PNG image data, 1024 x 4988, 8-bit/color RGBA, non-interlaced
ra:app(master) ryan$ file ramen-c.png 
ramen-c.png: PNG image data, 1024 x 4988, 8-bit/color RGBA, non-interlaced

Is there some default option I should be changing in IMGkit to get this better efficiency?

Here are the images in question:

test: test.png

test-c: test-c.png

ramen (which I won't embed because it's 20MB): ramen.png

ramen-c: ramen-c.png

ryana avatar Oct 24 '15 15:10 ryana