Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image blobs are 1 octet too short? encoding? #91

Open
joshco opened this issue Jan 10, 2016 · 1 comment
Open

image blobs are 1 octet too short? encoding? #91

joshco opened this issue Jan 10, 2016 · 1 comment

Comments

@joshco
Copy link

joshco commented Jan 10, 2016

I'm trying to use imgkit in a rails controller with send_data and imgkit.to_png
This results in an image sent that is 1 byte too short and a broken image.
However, if I save the data to a file with imgkit.to_file, and then tell rails to send that with send_file it works.
I'm on Windows 10 x64, ruby 2.0, rails 4.2.0, imgkit 1.6.1, wkhtmltoimage 0.12.2.4

I can't figure out what is wrong, but my hunch is that this is an encoding issue. The strings(blobs) show up as ASCII-8BIT

    kit = IMGKit.new(html)
    image_data = kit.to_png
    file = kit.to_file('myfile.png')
    send_file('myfile.png', :type => "image/png", :disposition => 'inline') # THIS WORKS
    send_data image_data, type: 'image/png', :disposition => 'inline' #THIS DOES NOT
@joshco
Copy link
Author

joshco commented Jan 10, 2016

More info. I tried re-reading the file that was created with .to_file with IO.binread('myfile.png') into a string variable and then and using that string as a param with send_data and that works.
It looks like the inter-process pipe between imgkit and the wkhtmltoimage executable is where the problem arises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant