Hello there, I need to scale down a .tiff file and turn it into a .png
file. I’ve thought of several options to doing this but as a newbie I’d
appreciate if somebody could please provide some direction as to which
option to pursue:
OPTION 1: use someone else’s
I looked in core and stdlib. I found nothing. Then I searched for ‘tiff’
at rubyforge.org but also nothing.
Am I going about trying to find an appropriate gem in the correct
manner? (I can’t be the only person ever needing to this!)
OPTION 2: imagemagick
I’ve found ImageMagick – Convert, Edit, or Compose Digital Images It does not have
a ruby interface. But I can use this tool from the command line. Lets
say I install imagemagick on windows which is also where I will run my
convert_tiff_to_png.rb script from. Lets say I’ve put imagemagick in my
system path too. Looking at the imagmagick docs:
So within a ruby script, how do I say “run this line as if from the
windows command prompt”?
OPTION 3: ms paint
If I open a .tiff file in paint, I simply do Edit > resize and File >
save as… and select .png
Its really easy in paint. I just have to do this a couple of thousand
times so I really need this in ruby. Is there an easy way to drive paint
from ruby?
I get the feeling imagemagick is my best/easiest option?
On Mon, Aug 15, 2011 at 8:20 PM, Michelle P. [email protected] wrote:
OPTION 2: imagemagick
I’ve found ImageMagick – Convert, Edit, or Compose Digital Images It does not have
a ruby interface. But I can use this tool from the command line. Lets
say I install imagemagick on windows which is also where I will run my
convert_tiff_to_png.rb script from. Lets say I’ve put imagemagick in my
system path too. Looking at the imagmagick docs:
Actually, there’s RMagick (and RMagick 2 for Ruby 1.9.x), which are
Ruby bindings for ImageMAgick (which will need to be installed,
obviously).
For Windows, instaling ImageMagick + RMagick is fairly simple. Just
download this[1] and follow instructions inside. (Unfortunately, this
only works with Ruby 1.8.6.)
But do you really need to do this in Ruby? If you just want to process
a couple hundred images once, I’d recommend IrfanView and it’s Batch
Conversion.
Thanks very much Phillip and Bartosz for your replies.
(Unfortunately, this only works with Ruby 1.8.6.)
Bartosz, regarding the installation. I have to use 1.9.2. Phillip’s link
says I need to then install rmagick2 (windows) with the stated
prerequisite of “Ruby 1.8.2 and later, including Ruby 1.9…” If I just
install Ruby1.9.2-p290 from rubyinstaller.org will the requirement of
1.8.2 be satisfied or do I physically have to install 1.8.2 separately?
But do you really need to do this in Ruby?
I left a bit of information in a (lost) effort to be concise. I’m using
this script to communicate with a webapp called mingle from thoughtworks-studios.com . The script will be called once initially for
all existing cards in mingle. And then every time there after when
we create a new card in mingle. For us a card in mingle represents a job
we have to do in our engineering workshop. Each job has a drawing
showing the machinist knows what to make. Mingle only previews .png
files but our clients gives their drawings to us in .tiff format. I need
to convert it to .png on the fly. Which is why I need this working in
ruby. The .tiff collection of drawings is every growing as are the jobs
we add. I can’t do it once off.
Oooof I feel like I’ve just had one of those conversations where I’ve
bored everyone with the detail!
Thanks Jon, I followed the instructions on phosphor-escence.
Unfortunately I couldn’t get the rmagick gem to install(see attachment).
If anyone has any ideas I’d be real interested to hear them.
But I did get ImageMagick to install and instead (of using rmagick) I
just issue ImageMagick commands directly from my ruby code. Not as nice
but it works.
For completeness of this post here are my exact steps:
[4]
Instead of using RMagick, I just call the ImageMagick CMD command
directly from my ruby script:-
if (system(‘C:\ImageMagick-6.7.1-Q16\convert.exe convert.tif
new.png’))
puts “yahoo! converting tif to png worked”
else
puts “oof it failed”
end
[lastly]
If I could have gotten the rmagick gem to install, this is how I would
do the same command in [4] but in nicer ruby code:
require ‘RMagick’
png = Magick::ImageList.new(“convert.tif”)
png = png.scale(300, 300)
png.write “new.png”
Bartosz, regarding the installation. I have to use 1.9.2. Phillip’s link
says I need to then install rmagick2 (windows) with the stated
prerequisite of “Ruby 1.8.2 and later, including Ruby 1.9…” If I just
install Ruby1.9.2-p290 from rubyinstaller.org will the requirement of
1.8.2 be satisfied or do I physically have to install 1.8.2 separately?
My link is to a precompiled binary version of the gem, built for 1.8.6
RMagick2 itself should work with 1.9, if you build it properly.
There are similar prebuilt ones for Ruby 1.8.5 and some others, but
unfortunately none for 1.9.x, and I think building RMagick yourself on
Windows is quite a hassle (I’ve never really tried it though - it
didn’t work at the first time, so I stuck to 1.8.6 when I need to use
it).