How can i load image and display it using ruby?

Which library/api is used to load and display image using ruby?
How can i do it?
Can anyone post complete code?

On 05/03/2012 12:34 PM, gmspro gmspro wrote:

Which library/api is used to load and display image using ruby?

You have several options. Here’s how to do it using RMagick¹:

require ‘RMagick’
images = Magick::Image.read(filename)
images[0].display

RMagick depends on ImageMagick² or GraphicsMagick³ being installed on
your system.


Lars H.

[1] http://rmagick.rubyforge.org/
[2] http://www.imagemagick.org/
[3] http://www.graphicsmagick.org/

How would i install rmagic?

gem install rmagic

Error:

Fetching: rmagick-2.13.1.gem ( 81%)
Fetching: rmagick-2.13.1.gem (100%)
Building native extensions. This could take a while…
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.

    /home/user1/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb

checking for Ruby version >= 1.8.5… yes
checking for gcc… yes
checking for Magick-config… no
Can’t install RMagick 2.13.1. Can’t find Magick-config in
/home/user1/.rvm/bin:/home/user1/.rvm/gems/ruby-1.9.2-p180/bin:/home/user1/.rvm/gems/ruby-1.9.2-p180@global/bin:/home/user1/.rvm/rubies/ruby-1.9.2-p180/bin:bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/home/user1/.rvm/rubies/ruby-1.9.2-p180/bin/ruby

Gem files will remain installed in
/home/user1/.rvm/gems/ruby-1.9.2-p180/gems/rmagick-2.13.1 for
inspection.
Results logged to
/home/user1/.rvm/gems/ruby-1.9.2-p180/gems/rmagick-2.13.1/ext/RMagick/gem_make.out

On 05/03/2012 01:45 PM, gmspro gmspro wrote:

How would i install rmagic?

The last line of my previous reply contains a pretty big hint.

If you get stuck, there’s also this:
http://rmagick.rubyforge.org/install-faq.html

gmspro gmspro wrote in post #1059401:

Which library/api is used to load and display image using ruby?
How can i do it?
Can anyone post complete code?

Install gtk2 in system,
Install gem Ruiby,
for testing, run

ruiby_demo

Then try this :

require ‘Ruiby’

Ruiby.app do
stack do
ARGV.each { |fn|
label File.exist?(fn) ?
“#”+fn :
“Oups !! unknown file ‘#{fn}’”
}
end
end

(label show a image file if args start with #, else args text)

There is a jruby-specific library which can do this simply:

jruby -rubygems samples/file_view.rb ~/Pictures/hand_sanitizer.jpg

file_view.rb:
require ‘image_voodoo’
ImageVoodoo.with_image(ARGV[0]) { |img| img.preview }

Some other samples:

image_voodoo also comes with a command-line util:

jruby -S image_voodoo --preview --flip_vertically --preview
~/Pictures/hand_sanitizer.jpg

image_voodoo --help for other options

-Tom

jruby -S image_voodoo --preview –

On Thu, May 03, 2012 at 08:45:27PM +0900, gmspro gmspro wrote:

How would i install rmagic?

gem install rmagic

For Ruby versions after 1.9.0, I think you need to install rmagick2
instead of rmagick. Someone correct me if I’m mistaken.

2012/5/4 Chad P. [email protected]:

On Thu, May 03, 2012 at 08:45:27PM +0900, gmspro gmspro wrote:

How would i install rmagic?

gem install rmagic

For Ruby versions after 1.9.0, I think you need to install rmagick2
instead of rmagick. Someone correct me if I’m mistaken.

Note, there is no such gem as “rmagick2”. There is just “rmagick”,
which happens to have had two major versions, 1.x and 2.x.

– Matma R.

gmspro gmspro wrote in post #1059401:

Which library/api is used to load and display image using ruby?
How can i do it?
Can anyone post complete code?

hi there -

how about Shoes? http://shoesrb.com/

green Shoes (GitHub - ashbb/green_shoes: Green Shoes is one of the colorful Shoes written in pure Ruby.) is wicked easy to
install and use:

gem install green_shoes

once it’s installed, you can just do this:

require ‘green_shoes’

Shoes.app do
image ‘TradyBlix.png’ #(change the filename!)
end

hth-

  • j