Forum: Ruby Converting .tiff -to-> .png?

7f17ddbbc9cfad81e9bf71b791292d93?d=identicon&s=25 Michelle Pace (michelle1)
on 2011-08-15 20:20
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?


Thank-you, michelle
A70c94da27a322b077742779f62ef81d?d=identicon&s=25 Phillip Gawlowski (Guest)
on 2011-08-15 20:28
(Received via mailing list)
On Mon, Aug 15, 2011 at 8:20 PM, Michelle Pace
<michelle@michellepace.com> wrote:
>
> 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:

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
39093dd2b68b68960fecd0fe2b9a5045?d=identicon&s=25 Bartosz Dziewoński (matmarex)
on 2011-08-15 21:59
(Received via mailing list)
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/RMagic...



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>:
7f17ddbbc9cfad81e9bf71b791292d93?d=identicon&s=25 Michelle Pace (michelle1)
on 2011-08-16 08:20
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 again, michelle
39093dd2b68b68960fecd0fe2b9a5045?d=identicon&s=25 Bartosz Dziewoński (matmarex)
on 2011-08-16 11:00
(Received via mailing list)
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?

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
D469019a435a5dbd5c792016fdf67a0b?d=identicon&s=25 Jon Forums (jonm)
on 2011-08-16 15:36
7f17ddbbc9cfad81e9bf71b791292d93?d=identicon&s=25 Michelle Pace (michelle1)
on 2011-08-23 13:37
Attachment: gem_make.out (696 Bytes)
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....
* 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'
  png = Magick::ImageList.new("convert.tif")
  png = png.scale(300, 300)
  png.write "new.png"


Cheers Michelle
Ed797291050037fced550e8299811bc6?d=identicon&s=25 "Gábor Pintér" <pinter.kategora@gmail.com> (Guest)
on 2011-08-23 13:41
(Received via mailing list)
unsubscribe
927d157b8ddf72d3eb115c4e4a6e6263?d=identicon&s=25 arron w. (arron_w)
on 2013-11-06 09:47
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.