ImageMagick + rmagick + unknown format: png

24 02 2009

Recently I ran into a problem with ImageMagick, rmagick and my Rails application. Somehow my environment was messy and it included varied versions of ImageMagick. This is what I did to solve the problem:

1. Removed all installations of ImageMagick

There was one version that was compiled and installed. I uninstalled it doing this:

# go to wherever you have your make file

cd /usr/local/ImageMagick-6.4.9-4

# run make uninstall with sudo, this rollbacks make install

sudo make uninstall

There was another version that was installed using yum. I uninstalled it doing this:

sudo yum erase ImageMagick

2. Removed all ImageMagick directories from my environment, like this:

I had to repeat the following step a couple of times with different directories:

# you must have root privileges

# this updates the filesystem database to use locate

updatedb

# this finds whatever files/directories have ImageMagick in it

locate ImageMagick

# this gets rid of the ImageMagick library (which wasn’t getting used, anyway..)

sudo rm -r /usr/local/lib/ImageMagick-6.4.9

Basically I got rid of all the unnecessary ImageMagick directories (since I had already uninstalled ImageMagick)

3. Installed libpng using yum:

sudo yum install libpng

4. Installed ImageMagick-devel using yum:

Before I did this, I tried to install rmagick’s gem. (just for the fun of it)

That didn’t work because rmagick didn’t find ImageMagick in the environment.

sudo yum install Magick-devel

5. Installed rmagick

sudo gem install rmagick

6. Restarted my application

I don’t know if this step was necessary, but I did it anyway.

That solved the “unknown format: png” error that I was getting. In days like today I love yum.



setting up sendmail in EC2

22 02 2009

Somehow I noticed that our Drupal wasn’t sending email notifications as it was supposed to. We just migrated a CMS to one of our EC2 instances. I figured that Drupal was using sendmail, as I couldn’t find any SMTP configuration in the administration section.

First of all, I checked if sendmail was running:

ps -aux | grep sendmail

That showed me that it wasn’t running.

Then I started it as root:

/usr/sbin/sendmail -bd -q20m

Then I added our domain name to the list of local host names at /etc/mail/local-host-names

Also, I configured submit.cf to use our domain: aycron.com – You can find submit.cf at /etc/mail/submit.cf and modify it to look like this:

# my official domain name
# … define this only if sendmail cannot automatically determine your domain
#Dj$w.Foo.COM
Dj$w.aycron.com

Finally, I tested that sendmail was working:

[etagwerker@dev-001 ~]$ /usr/sbin/sendmail -F”Ernesto Tagwerker” etagwerker@aycron.com
Hello, this is a test. 1. 2. 3. Testing.
Bye.
.

This totally worked!



Rails/Ruby integration with SOAP

15 02 2009

The other day I needed to integrate with Lyris ListManager using their API. Their API uses SOAP and my application is on Rails. I started looking for information about Ruby/Rails + SOAP integration and found this article first: http://wiki.rubyonrails.org/rails/pages/HowToUseSOAP4RWithRails

That’s how I started. Assuming that you have a running SOAP service on mylistmanager.com:82, here are the steps I took:

1. Install soap4r’s gem (if you don’t have it already)

[etagwerker@benteveo]$ sudo gem install soap4r
Password:
Successfully installed httpclient-2.1.3.1
Successfully installed soap4r-1.5.8
2 gems installed
Installing ri documentation for httpclient-2.1.3.1…
Installing RDoc documentation for httpclient-2.1.3.1…

Unfortunately, that rubyonrails.org article was not clear enough for what I wanted to do. Basically, I want to consume a SOAP service. So I needed to create a SOAP client stub that I could use from my application. After googling for information on wsdl2ruby, I found this really good article: http://www.brendonwilson.com/blog/2006/04/02/ruby-soap4r-wsdl-hell

2. Generate your client stub with wsdl2ruby

[etagwerker@benteveo]$ wsdl2ruby.rb –wsdl http://mylistmanager.com:82/?wsdl –type client –force
I, [2009-02-11T11:06:26.012941 #7276]  INFO — app: Creating class definition.
I, [2009-02-11T11:06:26.013108 #7276]  INFO — app: Creates file ‘lmapi.rb’.
I, [2009-02-11T11:06:26.117915 #7276]  INFO — app: Creating mapping registry definition.
I, [2009-02-11T11:06:26.118102 #7276]  INFO — app: Creates file ‘lmapiMappingRegistry.rb’.
I, [2009-02-11T11:06:26.234855 #7276]  INFO — app: Creating driver.
I, [2009-02-11T11:06:26.235469 #7276]  INFO — app: Creates file ‘lmapiDriver.rb’.
I, [2009-02-11T11:06:26.308501 #7276]  INFO — app: Creating client skelton.
I, [2009-02-11T11:06:26.308847 #7276]  INFO — app: Creates file ‘lmapiClient.rb’.
I, [2009-02-11T11:06:26.321677 #7276]  INFO — app: End of app. (status: 0)

This generated a bunch of Ruby files that are very useful for the integration. Basically, it makes everything more simple. You don’t need to worry about SOAP messages, responses, etc.. You just use the classes in that stub to interact with your SOAP service.

3. Move the client stub files to your /lib directory (in your Rails project)

This will make your stub client classes accessible to your application

4. Add soap4r to your boot.rb file

I don’t know where I found this step, but I was getting an error with SOAP when trying to use SOAP classes form my application. Your boot.rb should look like this:

def load_rubygems
require ‘rubygems’
gem ’soap4r’

Basically, I added gem ’soap4r’ which imports the SOAP classes in my application.

5. Fire up your Rails console (./script/console in your Rails project) and test it!

Luckily, I found a really thorough example here: http://markthomas.org/2007/09/12/getting-started-with-soap4r - However, if you look at the files you generated with wsdl2ruby, you will find a lot of useful and descriptive information (as code and comments)

To test it, I include the lmapiDriver.rb (present in the /lib directory), I create a driver, I give it the user credentials and I start using it (selectLists and apiVersion are both Lyris SOAP API methods)

require “lmapiDriver.rb”
driver = LmapiSoap.new

#Add authentication
wsdl = “http://mylistmanager.com:82/?wsdl”
user = “yourusername”
pass = “yourpassword”
driver.options["protocol.http.basic_auth"] << [wsdl,user,pass]

# Print the name of all lists
lists = driver.selectLists(”,”)

driver.apiVersion

# If it all worked out fine, you should see:
# => “10.2″

I found this integration really simple. wsdl2ruby.rb is an amazing tool for speeding things up.