Hmm, I know I grew up cutting teeth on C, but the "overhead" of getting
decent development environment, and "syncing" your compiler version
to that of who-ever wrote the code originally gets to be fun.
Its even worse when your going cross platform. (Yes I now prefer to
do my coding in ruby whenever possible).
I was reading thru ruby group on goole, about how to speed up the "png"
gem without using inline. I'm going to give that a try. Then I can use
the resolve in my pdftoruby tool.
Should be interesting, will update the article after I finish.
Wednesday, April 23, 2008
Geting Ruby png1.0.0 to work in windows
I need to be able to save "png" files out of my pdftoruby application.
My big problem was to take a "rgb" file, and write it, without using something
heave like ImageMagik. (Which seems like everyone complains about)
So my first choice was "png", but the latest version of png is not "pure" ruby.
Version 1.0.0 is "pure". The reason this is important, is that with the 1.1.0
release of png gem, you have to use "inline" and that then requires you to
use the "latest" compiler.
I've installed, and reinstalled png several times, but it seems to never work,
then finally I found a "mention" in a old ruby-talk message thread that on windows
you need the "b" open on the open. (A following comment said it had been patched).
Well decicded to go look at the source, and sure enough, its not got the "b" option
on the open.
So do the following:
gem install --version 1.0.0 png
Then go to the png directory
cd \ruby\lib\ruby\gems\1.8\gems\png-1.0.0\lib
And edit png.rb
vi png.rb # Use the editor of your choice
def save(path)
File.open(path, "wb") do |f| #Must add the "b" next to the "w"
#here for windows to work
f.write [137, 80, 78, 71, 13, 10, 26, 10].pack("C*") # PNG signature
f.write PNG.chunk('IHDR',
[ @height, @width, @bits, 6, 0, 0, 0 ].pack("N2C5"))
# 0 == filter type code "none"
data = @data.map { |row| [0] + row.map { |p| p.values } }.flatten
f.write PNG.chunk('IDAT', Zlib::Deflate.deflate(data.pack("C*"), 9))
f.write PNG.chunk('IEND', '')
end
end
Now png examples will work, and I can get back to business.
(I've seen some nice pure ruby optizations in the threads, will implemented those in pdfto ruby)
My big problem was to take a "rgb" file, and write it, without using something
heave like ImageMagik. (Which seems like everyone complains about)
So my first choice was "png", but the latest version of png is not "pure" ruby.
Version 1.0.0 is "pure". The reason this is important, is that with the 1.1.0
release of png gem, you have to use "inline" and that then requires you to
use the "latest" compiler.
I've installed, and reinstalled png several times, but it seems to never work,
then finally I found a "mention" in a old ruby-talk message thread that on windows
you need the "b" open on the open. (A following comment said it had been patched).
Well decicded to go look at the source, and sure enough, its not got the "b" option
on the open.
So do the following:
gem install --version 1.0.0 png
Then go to the png directory
cd \ruby\lib\ruby\gems\1.8\gems\png-1.0.0\lib
And edit png.rb
vi png.rb # Use the editor of your choice
def save(path)
File.open(path, "wb") do |f| #Must add the "b" next to the "w"
#here for windows to work
f.write [137, 80, 78, 71, 13, 10, 26, 10].pack("C*") # PNG signature
f.write PNG.chunk('IHDR',
[ @height, @width, @bits, 6, 0, 0, 0 ].pack("N2C5"))
# 0 == filter type code "none"
data = @data.map { |row| [0] + row.map { |p| p.values } }.flatten
f.write PNG.chunk('IDAT', Zlib::Deflate.deflate(data.pack("C*"), 9))
f.write PNG.chunk('IEND', '')
end
end
Now png examples will work, and I can get back to business.
(I've seen some nice pure ruby optizations in the threads, will implemented those in pdfto ruby)
Subscribe to:
Posts (Atom)