Converting .tiff -to-> .png?

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:

$magick>convert -size 100x100 image.tiff image.png

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?

So this installs on windows

--
Posted via http://www.ruby-forum.com/.

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).

It can be a bit of a hassle to install, though:

http://rmagick.rubyforge.org/install-faq.html

···

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:

--
Phillip Gawlowski

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz

Do the following blog contributions from our
https://github.com/oneclick/rubyinstaller/wiki/Tutorials page help?

http://www.waydotnet.com/blog/2010/02/rmagick-on-ruby-1-9-1-i386-mingw32-work-d/

Also, you might scan past messages from our google group

http://groups.google.com/group/rubyinstaller/search?group=rubyinstaller&q=rmagick

Jon

···

--
Posted via http://www.ruby-forum.com/.

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:

[0]
I installed ruby192 as well as the DevKit using
http://rubyinstaller.org/ on windows 7.

[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"

Cheers Michelle

Attachments:
http://www.ruby-forum.com/attachment/6540/gem_make.out

···

--
Posted via http://www.ruby-forum.com/.

I have never tried to convert .tiff to .png before. I was using this
Tiff conversion tool:
http://www.yiigo.com/guides/csharp/how-to-tiff-convert.shtml
You can have a try. I hope it helps.

···

--
Posted via http://www.ruby-forum.com/.

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.)

[1] http://rubyforge.org/frs/download.php/64917/RMagick-2.12.0-ImageMagick-6.5.6-8-Q8.zip

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.

-- Matma Rex

···

2011/8/15 Phillip Gawlowski <cmdjackryan@gmail.com>:

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).

It can be a bit of a hassle to install, though:

http://rmagick.rubyforge.org/install-faq.html

--
Phillip Gawlowski

phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibniz

unsubscribe

···

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:

[0]
I installed ruby192 as well as the DevKit using
http://rubyinstaller.org/ on windows 7.

[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"

Cheers Michelle

Attachments:
http://www.ruby-forum.com/attachment/6540/gem_make.out

--
Posted via http://www.ruby-forum.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?

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! :slight_smile:

thanks again, michelle

···

--
Posted via http://www.ruby-forum.com/\.

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?