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 http://www.imagemagick.org/script/index.php 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 Pace <michelle@michellepace.com> 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:
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:
[1]
Installed ImageMagick-6.7.1-10-Q16-windows-dll.exe
* downloaded from http://www.imagemagick.org/script/binary-releases.php#windows
* I installed to "C:\ImageMagick-6.7.1-Q16" (no spaces!!)
* ticked "Add application directory to your system path"
* ticked "Install development headers & libraries for C and C++"
[2]
I confirmed ImageMagick works via command prompt with:
* % C:\ImageMagick-6.7.1-Q16\convert.exe convert.tif -resize 10% new.png
[?]
I attempted to instal the 'rmagick' gem with the below command. I got an
error. (see attachment) and gave up.
* % gem install rmagick --platform=ruby --
--with-opt-lib=C:/ImageMagick-6.7.1-Q16/lib
--with-opt-include=C:/ImageMagick-6.7.1-Q16/include
[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'
jpg = Magick::ImageList.new("doc.jpg")
thumb = jpg.scale(300, 300)
thumb.write "doc.png"
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.
On Mon, Aug 15, 2011 at 8:20 PM, Michelle Pace > <michelle@michellepace.com> 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).
On Tue, Aug 23, 2011 at 1:37 PM, Michelle Pace <michelle@michellepace.com>wrote:
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:
[1]
Installed ImageMagick-6.7.1-10-Q16-windows-dll.exe
* downloaded from ImageMagick – Download
* I installed to "C:\ImageMagick-6.7.1-Q16" (no spaces!!)
* ticked "Add application directory to your system path"
* ticked "Install development headers & libraries for C and C++"
[2]
I confirmed ImageMagick works via command prompt with:
* % C:\ImageMagick-6.7.1-Q16\convert.exe convert.tif -resize 10% new.png
[?]
I attempted to instal the 'rmagick' gem with the below command. I got an
error. (see attachment) and gave up.
* % gem install rmagick --platform=ruby --
--with-opt-lib=C:/ImageMagick-6.7.1-Q16/lib
--with-opt-include=C:/ImageMagick-6.7.1-Q16/include
[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'
jpg = Magick::ImageList.new("doc.jpg")
thumb = jpg.scale(300, 300)
thumb.write "doc.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?
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. But then also every time there after when
creating new cards. For us a card in mingle represents a job we have to
do in our engineering workshop. Each job has a drawing. But our clients
give it to us .tiff format so I need to convert it to .png on the fly.
Oooof I feel like I've just had one of those conversations where I've
bored everyone with the detail!
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).
-- Matma Rex
···
2011/8/16 Michelle Pace <michelle@michellepace.com>:
Thank-you Phillip and Bartosz.
(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?