I find it’s painful to go back to Photoshop just to generate a gradient, especially when I’m modifying the CSS at the very same time to find the right colors.
Here’s the Rake task I use now to quickly generate a gradient background:
desc "Generate the gradient background"
task :gradient do
require 'rmagick'
include Magick
WIDTH = 1
HEIGHT = 154
gradient = GradientFill.new(0, 0, WIDTH, 0, "#84704E", "#99906E")
image = Image.new(WIDTH, HEIGHT, gradient)
image.write("images/gradient.jpg")
end
I put this code under version control, in a Rakefile placed inside the Mephisto (in this case) theme itself.
The corresponding CSS contains:
body {
padding: 0em;
margin: 0em;
color: #333333;
font-family:"Helvetica Neue",Helvetica,Arial,Sans-Serif;
background:#99906E url(../images/gradient.jpg) repeat-x;
}
If I need to DRY things out, it’s possible to extract the body background color from the CSS, to use it in the GradientFill.new call:
background_color = IO.read("stylesheets/main.css").grep(/background:#([\S]+)/) { $1 }
gradient = GradientFill.new(0, 0, WIDTH, 0, "#84704E", background_color)
Alternatively if you generate your CSS with SASS you could tap into the SASS source directly.
That’s it. I’ve used this on the blog you’re currently reading and also on my mind-mapping, self-improvement and useful software blog.
I’ll experiment more with shadows and other little customizations when required.
RMagick tutorials
I found the following links helpful while looking for information to do that:
- Alpha compositing part 1
- Alpha compositing part 2
- Render great looking collages with ruby and rmagick
- Faire un logo avec RMagick
The comments system is brand new - don't be afraid to comment!
- Monitoring File Changes and Getting Notified via Growl (February 14th, 2010)
- How to use Google Calendar and Rufus-Google for Basic Time Tracking (November 27th, 2009)
- Using JRuby to prototype VST plugins (November 17th, 2009)
- Introducing Learnivore.com (September 15th, 2009)
- How to create small, unique tokens in Ruby (July 2nd, 2009)
- Detecting Which Ruby Interpreter is Running (JRuby, IronRuby) (March 4th, 2009)
- How to create an empty Rails Edge application (January 28th, 2009)
- How to Freeze Gems with Rails >= 2.1 (December 23rd, 2008)
- Thoughts on IronRuby and .Net Testing (December 1st, 2008)
- How to Retrieve Delicious Tags and Number of Bookmarks for a Given Url (November 30th, 2008)
- Fixing Symbol not found _rl_filename_completion_function (November 6th, 2008)
- Analyzing Your GMail History (September 18th, 2008)
- Data Visualization with Ruby and RMagick - Where Are Those Bikes ? (March 31st, 2008)
- All-Time Classics: a Selection of Recommended Books for Software Developers (February 23rd, 2008)

