# Writing image into a ruby file

**URL:** <https://www.ruby-forum.com/t/writing-image-into-a-ruby-file/178896>\
**Category:** FXRuby\
**Created:** [November 13, 2009, 4:46am UTC](https://www.ruby-forum.com/t/writing-image-into-a-ruby-file/178896 "2009-11-13T04:46:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [November 13, 2009, 4:46am UTC](https://www.ruby-forum.com/t/writing-image-into-a-ruby-file/178896/1 "2009-11-13T04:46:28Z")

</div>

hi all,

I remember (very) long time ago, there was some information posted about  
loading an image into a ruby file. I am trying to look for the sniplet  
of the code but couldn’t find anytying. Just wondering if anyone could  
help.

This is some of the extract of the code:-

#I am trying to write the content of the icon into an include file.

def loadIcon(file)  
begin  
File.open(file, “rb”) do |f|  
icon = FXICOIcon.new(getApp(), f.read)  
end  
icon  
rescue  
raise RuntimeError, “Couldn’t load icon: #{file}”  
end  
end

#I’m trying load ‘Australia-Flag.ico’ and store it as a constant  
‘aus.rb’.  
filename = ‘c:\FXRUbySample\Australia-Flag.ico’  
icon75 = loadIcon(filename)

File.new(‘c:\FXRubySample\aus.rb’, ‘wb’)  
File.open(‘c:\FXRubySample\aus.rb’,‘wb’) do |f|  
#puts icon75  
f.syswrite icon75  
end

#none of the puts and syswrite works.
