Coming from a Rails background I was hoping I could render a transparent pixel gif. To do this on Rails I simply
gif_data = "GIF89a\x01\x00\x01\x00\x80\xFF\x00\xC0\xC0\xC0\x00\x00\x00!\xF9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x01\x012\x00;"
respond_to do |format|
format.gif { render text: gif_data, content_type: "image/gif" }
end
Would appreciate some cleaner way to do it than my own.
After some googling and learning string encodings. I converted the Hex code of the actual transparent gif
47 49 46 38 39 61 01 00 01 00 80 00 00 00 00 00 FF FF FF 21 F9 04 01 00 00 00 00 2C 00 00 00 00 01 00 01 00 00 02 01 44 00 3B
using Hexate package into this
<<71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 0, 0, 0, 0, 0, 255, 255, 255, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 1, 68, 0, 59>>
so to use this in a Phoenix Controller I can
gif_data = <<71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 0, 0, 0, 0, 0, 255, 255, 255, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 1, 68, 0, 59>>
conn = put_resp_content_type(conn, "image/gif")
text conn, gif_data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With