<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <author>Simon Schoeters</author>
    <content>&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Check out this great &lt;a href="http://onrails.org/articles/2009/09/04/rmagick-from-source-on-snow-leopard" title="RMagick (from source) on Snow Leopard" class="ext"&gt;installation script&lt;/a&gt; by Solomon White if you are running Snow Leopard. It worked perfect here.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.imagemagick.org/" title="ImageMagic: Convert, edit and compose images" class="ext"&gt;ImageMagick&lt;/a&gt; is a command line utility to convert, edit and compose images that is typically used in combination with a programming language. The Ruby interface is called &lt;a href="http://rmagick.rubyforge.org/" title="Graphics Processing for Ruby and Ruby on Rails" class="ext"&gt;RMagick&lt;/a&gt;. The RMagick interface makes image editing in Ruby painless, if you get it installed that is. &lt;a href="http://www.graphicsmagick.org/" title="GraphicsMagick image processing system" class="ext"&gt;GraphicsMagick&lt;/a&gt; is another image editor that can be used in combination with RMagick but I didn't look into that.&lt;/p&gt;

&lt;p&gt;There are numerous ways to get ImageMagick and RMagic installed on Mac OS X and I don't even remember all the different ways I tried but the following method seems to work. MacPorts may install versions of the software that are out-of-date, so check this first if that's an important issue for you.&lt;/p&gt;

&lt;h3&gt;MacPorts&lt;/h3&gt;

&lt;p&gt;Let's start with installing &lt;a href="http://trac.macosforge.org/projects/macports/wiki" title="MacPorts wiki" class="ext"&gt;MacPorts&lt;/a&gt;, formerly called DarwinPorts. This port automatically installs ImageMagick and all the dependent libraries. You need &lt;a href="http://developer.apple.com/tools/xcode/"&gt;Xcode&lt;/a&gt; installed for MacPorts to work. Installing MacPorts is very straightforward and shouldn't be a problem, &lt;a href="http://svn.macosforge.org/repository/macports/downloads/" title="MacPort downloads" class="ext"&gt;download&lt;/a&gt; the newest MacPorts-x.x.x.dmg and install the package.&lt;/p&gt;

&lt;p&gt;Once MacPorts is installed you can install ImageMagick via Terminal. The path to the port binary may be different but I suppose it's the default installation directory, isn't it?&lt;/p&gt;

&lt;samp&gt;# sudo /opt/local/bin/port install ImageMagick&lt;/samp&gt;

&lt;p&gt;This may take a while and you'll see MacPorts downloading and installing ImageMagick, done? Let's get on with RMagick the same way we got ImageMagick:&lt;/p&gt;

&lt;samp&gt;# sudo /opt/local/bin/port install rb-rmagick&lt;/samp&gt;

&lt;p&gt;Again, waiting, I think it took about 15 minutes to finish.&lt;/p&gt;

&lt;h3&gt;Gem&lt;/h3&gt;

&lt;p&gt;Next we'll need the RMagick gem as well. &lt;strong&gt;Note:&lt;/strong&gt; Installing the RMagick gem worked find on my old &lt;abbr title="PowerPC"&gt;PPC&lt;/abbr&gt; Mac but didn't work on the newer i386 (Intel) as the RMagick gem is built with the PPC headers. To install the gem set your ARCHFLAGS to i386 first. Here is how:&lt;/p&gt;
	
&lt;samp&gt;# export ARCHFLAGS='-arch i386'&lt;br /&gt;
# gem install rmagick&lt;/samp&gt;

&lt;p&gt;As &lt;span class="vcard"&gt;&lt;span class="fn n"&gt;&lt;span class="given-name"&gt;Jelle&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; points out in the comments you may want to add the local bin folder to your PATH. This will make it easier to run RMagick stuff that's installed in that directory without the need to specify the whole path each time. Add the following line to your .bash_login file and restart Terminal.&lt;/p&gt;

&lt;samp&gt;# vi ~/.bash_login&lt;br /&gt;
export PATH="/opt/local/bin/:$PATH"&lt;/samp&gt;

&lt;h3&gt;Sample conversion&lt;/h3&gt;

&lt;p&gt;Once this is done we can run a quick Ruby script to check if the installation went smoothly. Create the following create_thumb.rb script:&lt;/p&gt;

&lt;samp&gt;#!/usr/bin/env ruby&lt;br /&gt;
require 'RMagick'&lt;br /&gt;
img = Magick::Image.read('myimage.jpg').first&lt;br /&gt;
thumbnail = img.crop_resized(50, 50)&lt;br /&gt;
thumbnail.write 'myimage_thumb.jpg'&lt;/samp&gt;

&lt;p&gt;This creates a thumbnail image of 50px &amp;times; 50px from the myimage.jpg file and saves it as myimage_thumb.jpg. Make sure you have a JPEG image in the same directory and run the script.&lt;/p&gt;

&lt;samp&gt;# ruby create_thumb.rb&lt;/samp&gt;

&lt;p&gt;That's it, you should see a new file appearing in the current directory proving that it works!&lt;/p&gt;</content>
    <created-at type="datetime">2007-10-17T00:05:30+02:00</created-at>
    <id type="integer">9</id>
    <location-id type="integer">1</location-id>
    <permalink>imagemagick-rmagick-on-macosx</permalink>
    <title>Installing ImageMagick &amp;amp; RMagick for RoR on Mac OS X</title>
    <updated-at type="datetime">2009-12-14T11:32:10+01:00</updated-at>
  </post>
  <post>
    <author>Simon Schoeters</author>
    <content>&lt;p&gt;It's all about the map in this sites header today. The header background shows a dynamically generated map of the coordinates shown in the right top corner, or my last recorded place. I can select my current location (latitude and longitude) and the header background map is updated accordingly. So how exactly does this work?!&lt;/p&gt;

&lt;h3&gt;No Google or Yahoo! maps?&lt;/h3&gt;

&lt;p&gt;I integrated Yahoo! Maps first. The Yahoo! Maps look nice, the API is easy to use and well documented but the problem is that you are only allowed to play with these maps within limits placed on you by the API's terms and conditions. Below are some extracts from the &lt;a href="http://info.yahoo.com/legal/us/yahoo/maps/mapsapi/mapsapi-2141.html" title="Yahoo! Terms Center" class="ext"&gt;Yahoo! Maps API Terms of Use&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;You understand and agree that you must retain the attribution text and links contained within all Yahoo! Maps and Yahoo! Map images without alteration.&lt;/li&gt;
	&lt;li&gt;Your will not store or allow end users to store map imagery, map data or geocoded location information from the Yahoo! Maps APIs for any future use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would break these terms as I convert the original image to a grayscale version and store the map on the server for performance reasons so the Yahoo! Maps are out of the question. Google or Yahoo! Maps are great for out of the box functionalities but if you want more freedom you will probably have to look elsewhere (or pay for licenses if possible).&lt;/p&gt;

&lt;h3&gt;OpenStreetMap&lt;/h3&gt;

&lt;p&gt;Luckily for us there are other solutions out there. Let's take a look at &lt;a href="http://www.openstreetmap.org/" class="ext"&gt;OpenStreetMap&lt;/a&gt; for example. OpenStreetMap is a &amp;lsquo;wiki style&amp;rsquo; editable map, made by people like you and me. The content is available under the Creative Commons Attribution-ShareAlike 2.0 license which means anyone can use (and remix) the data as long as you share it with a similar license.&lt;/p&gt;

&lt;p&gt;This &amp;lsquo;Wikipedia-like&amp;rsquo; approach has some drawbacks as well: the map is incomplete and the data is not 100% reliable. On the other side you can correct or complete the map where needed. This may or may not be important for your project but I only needed a nice background image for this website so a general overview of the area is more than sufficient.&lt;/p&gt;

&lt;p&gt;OpenStreetMap has a RESTfull way to build a map image with a given latitude, longitude, zoom level and image size. Here is how (or see an example for &lt;a href="http://tah.openstreetmap.org/MapOf?lat=50.8668&amp;long=4.69714&amp;z=12&amp;w=200&amp;h=200" title="OpenStreetMap map of my home town" class="ext"&gt;my city&lt;/a&gt;):&lt;/p&gt;

&lt;samp&gt;http://tah.openstreetmap.org/MapOf?lat=&amp;lt;lat&amp;gt;&amp;amp;long=&amp;lt;long&amp;gt;&amp;amp;z=&amp;lt;zoom&amp;gt;&amp;amp;w=&amp;lt;width&amp;gt;&amp;amp;h=&amp;lt;height&amp;gt;&amp;amp;skip_attr=1&lt;/samp&gt;

&lt;p&gt;The &lt;code&gt;skip_attr&lt;/code&gt; defines if you want to include an &lt;abbr title="OpenStreetMap"&gt;OSM&lt;/abbr&gt; attirbution image in your map or not.&lt;/p&gt;

&lt;h3&gt;Start coding&lt;/h3&gt;

&lt;p&gt;The process flow:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;The current location is updated on the website,&lt;/li&gt;
	&lt;li&gt;a map of this new location is downloaded from a map server,&lt;/li&gt;
	&lt;li&gt;the downloaded map image is converted to grayscale and&lt;/li&gt;
	&lt;li&gt;the generated image is saved to disk.&lt;/li&gt;
&lt;/ol&gt;

&lt;p class="center"&gt;&lt;img src="/images/map_flow.gif" alt="Map flow" /&gt;&lt;/p&gt;

&lt;p&gt;We'll use &lt;a href="http://rmagick.rubyforge.org/" title="Graphics Processing for Ruby and Ruby on Rails" class="ext"&gt;RMagick&lt;/a&gt; and Ruby on Rails to convert the downloaded image to something else so make sure you have this installed first.&lt;/p&gt;

&lt;samp&gt;# Writes an image with a map of the location, the zoom ranges from 4 to 17&lt;br /&gt;
def map(latitude, longitude, width = 500, height = 500, zoom = 7)&lt;br /&gt;
   require 'RMagick'&lt;br /&gt;
   require 'open-uri'&lt;br /&gt;
   map_request_url = "http://tah.openstreetmap.org/MapOf?lat=#{latitude}&amp;amp;long=#{longitude}&amp;amp;z=#{zoom}&amp;amp;w=#{width}&amp;amp;h=#{height}"&lt;br /&gt;
   uri = URI.parse(map_request_url)&lt;br /&gt;
   map = Magick::ImageList.new&lt;br /&gt;
   map.from_blob(uri.read)&lt;br /&gt;
   map = map.quantize(256, Magick::GRAYColorspace)&lt;br /&gt;
   map.write(RAILS_ROOT + '/public/images/map.png')&lt;br /&gt;
end&lt;/samp&gt;

&lt;p&gt;That's it, this method downloads and converts the image and saves it in your images folder so from now on you can use this image in your website:&lt;/p&gt;

&lt;samp&gt;&amp;lt;img src="/images/map.png" alt="Map" /&amp;gt;&lt;/samp&gt;

&lt;h3&gt;More resources&lt;/h3&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.alistapart.com/articles/takecontrolofyourmaps" title="Take Control of Your Maps" class="ext"&gt;Take Control of Your Maps&lt;/a&gt; explains how to build you own map stack.&lt;/li&gt;
&lt;/ul&gt;</content>
    <created-at type="datetime">2008-04-15T18:14:57+02:00</created-at>
    <id type="integer">24</id>
    <location-id type="integer">1</location-id>
    <permalink>generated-maps</permalink>
    <title>Generated maps with Ruby on Rails</title>
    <updated-at type="datetime">2008-09-19T01:45:44+02:00</updated-at>
  </post>
</posts>
