[英]How to render a transparent gif pixel in Phoenix?
Coming from a Rails background I was hoping I could render a transparent pixel gif. 来自Rails背景,我希望我能渲染一个透明的像素gif。 To do this on Rails I simply
要简单地在Rails上执行此操作
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
我转换了实际透明gif的Hex代码
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 使用Hexate包进入此
<<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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.