Skip to content
accelerando

Tag Archives: RMagick

Handle EXIF data with ruby (and style…)

09-Mar-08

I use rmagick when it comes to deal with images. I’m not that disappointed like Zed Shaw with rmagick (but Zed is totally right when he points out on page 4: “[…] and is difficult to install (unless your computer is nearly exactly the same as the author’s).”), but when it comes to deal with EXIF, rmagick sucks big time.

After some searching i found another EXIF reader called “EXIF Reader” (EXIFR), which can be downloaded and installed from here or via gems.

I came mainly to this point becaus rmagick completly failed reading GPS data from my images (and it is hard to use with all other values).

EXIFR on the contrast cannot do image manipulation, so i needed both. Maybe i’m still just to new to ruby, but exifr gave me a hard time not reading the same image twice from file, once for rmagick and once for exifr.

I came up with the following solution:

require 'rubygems'
require 'RMagick'
require 'exifr'
image = Magick::ImageList.new("whatever_image.jpg")
exif_info = case image.format 
when 'JPEG'
  EXIFR::JPEG.new(StringIO.new(image.to_blob))
when 'TIFF'
  EXIFR::TIFF.new(StringIO.new(image.to_blob))
else
  nil
end

This uses rmagick to instantiate a magick image and then a StringIO object to build up the exif information if the image is a jpeg or a tiff image.

RMagick vs. the Rest of the World

24-Jul-07

Installing RMagick seems to be a major pain in the ass… On all systems i got my hands on.

On a fresh Ubuntu Feisty Fawn gems presented me this:

configure: error: C compiler cannot create executables

Hrmpf, ImageMagick was installed, gcc for sure… What did i miss?

   1. sudo apt-get install imagemagick
   2. sudo apt-get install libmagick9-dev
   3. sudo gem install rmagick

Well, the 2nd one…. Found here.

Ruby On Rails native MySQL Bindings Vs. RMagick

02-Jan-07

I’m writing this post in english in hope that more people find it useful…

Some times ago i really had bad problems installing the MySQL Gem 2.7 with Ruby 1.8.2 or 1.8.5 in conjunction with Rails 1.1.6 on Mac OS X 10.4

Compilation failed with:

Building native extensions. This could take a while…
mysql.c: In function ‘Init_mysql’:
mysql.c:2015: error: ‘ulong’ undeclared (first use in this function)
mysql.c:2015: error: (Each undeclared identifier is reported only once
mysql.c:2015: error: for each function it appears in.)
mysql.c:2015: error: parse error before numeric constant
mysql.c:2018: error: parse error before numeric constant
make: *** [mysql.o] Error 1
mysql.c: In function ‘Init_mysql’:
mysql.c:2015: error: ‘ulong’ undeclared (first use in this function)
mysql.c:2015: error: (Each undeclared identifier is reported only once
mysql.c:2015: error: for each function it appears in.)
mysql.c:2015: error: parse error before numeric constant
mysql.c:2018: error: parse error before numeric constant
make: *** [mysql.o] Error 1
ruby extconf.rb install mysql — –with-mysql-dir=/usr/local/mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… yes
checking for mysql_ssl_set()yes
checking for mysql.h… yes
creating Makefile

The gem would then install with Successfully installed mysql-2.7. Creepy!!! But that damn thing just didn’t work.

After quite some googling i found this one:

Running Rails on OS X with MySQL 5.0.24

It’s all about puting a little

#ifndef ulong 
#define ulong unsigned long
#endif

somewhere in “/usr/include/stdlib.h”.

This tipp is still necessary for MySQL 5.0.24+. Thanks again mate!!

But here the trouble starts….

I put the define in a nice little conditional just in case but bah… It would come down to hunt me…

For my project DailyFratze.de i also need RMagick. Again, the gem (1.14.1, 1.14.0 and 1.13) failed to compile but didn’t tell (on runtime it said “require “RMagick” LoadError: No such file to load — RMagick.so” … ) and installation from source did fail as well with:

setup.rb:655:in `command': system("make") failed (RuntimeError)
from setup.rb:664:in `make'
from setup.rb:1258:in `setup_dir_ext'
from setup.rb:1532:in `__send__'
from setup.rb:1532:in `traverse'
from setup.rb:1530:in `dive_into'
from setup.rb:1530:in `traverse'
from setup.rb:1534:in `traverse'
from setup.rb:1533:in `each'
... 8 levels...
from setup.rb:826:in `__send__'
from setup.rb:826:in `invoke'
from setup.rb:772:in `invoke'
from setup.rb:1578
make: *** [all] Error 1

Damn! After banging my head against the walls, reinstalling ImageMagick and all it’s depencies either direct from source, via i-installer and finally as mentioned here i took a break, visited some porn sites and stuff like that and though, hmm… stdlib.h….

I removed the little define and bam! It’s that easy, RMagick compiles just fine…

From the forums i found i guess other people with the same error message may have the same problem as i had…

I really wish installing a ruby on rails environment would be a less pain in the ass…. somewhere near as easy as developing with rails.

FastCGI und Standard Out

03-Oct-06

Gestern habe ich mich eine kleine Ewigkeit mit Ruby on Rails, RMagick und FastCGI geärgert.

Mit kleinen Schwierigkeiten habe ich meine ImageMagick Installation soweit gebracht, dass RMagick und Rails problemlos funktionierten.

Ziel war ein Imageupload mit anschliessender Verarbeitung durch RMagick. Da nicht immer eine temporäre Datei beim Upload ensteht, habe ich mich an ein Tutorial gehalten, wo folgende Code empfohlen wurde:

Magick::Image::read_inline(Base64.b64encode(feld.read)).first

Image::read_inline liest einen Base64 kodierten String. Soweit kein Problem, es funktionierte auch alles. Bis ich wieder auf Production und somit auf FastCGI umschaltete.

Die Anwendung stürzte nach dem Upload und der Verarbeitung der Bilder ab.

Im Apache error.log stand nur:

 FastCGI: comm with server "/Users/msimons/Entwicklung/rails/daily/public/dispatch.fcgi" aborted: error parsing headers: malformed header '/9j/4TseRXhpZgAASUkqAAgAAAALAA4BAgAgAAAAkgAAAA8BAgAFAAAAsgAA'

Drollig. Ich hab längere Zeit gesucht, bis ich den Hinweis fande, dass man beim FastCGI Prozess besser nicht ins Stdout schreibt. Genau das macht Base64.b64encode aber. Hatte mich schon geärgert, weil das verlangsamt das ganze natürlich bei großen Dateien.

Wenn ich obige Zeile in

Magick::Image::read_inline(Base64.encode64(feld.read)).first

ändere, ist alles in bester Ordnung. Der Malformed Header hatte ergo nichts mit RMagick zu tun. Toll.

Close
E-mail It