Thursday, February 16, 2012

Ruby 1.9.3 p125 has bean released

A few hours ago, Ruby 1.9.3 p125 has bean released. This is the security fix for Ruby OpenSSL. See the page below, for more information:

Of course, it's ready for MinGW. Install operations are as written in phosphorescence: Clean installation Ruby 1.9.3 preview1 with MinGW and MSYS.

Monday, February 13, 2012

FreeBSD is the easiest way to use Rails3 with nginx

To use ports on FreeBSD is the easiest way to use Rails3 with nginx.

(1) rubygem-rails port has configuration for rubygem-passenger

(2) rubygem-passenger port has configuration for nginx

(3) nginx port has configuration for many plug-ins.

BTW, rubygem-activerecord port has configuration for PostgreSQL.
So that you can choose BSD-License Friendly products (Ruby 1.9.3, nginx and PostgreSQL) to using Rails3.

Friday, February 10, 2012

specular reflection with mini_magick (2)

(continued from phosphorescence: specular reflection with mini_magick (1))

"Specular Reflection" consists of 4 operations.
  1. clone from original image and rotate it
  2. add transparency to cloned image
  3. combine original image and cloned one
  4. resize combined image
In this article, I introduce the operation of both (3) and (4) with referring ImageMagick's sample page and using mini_magick. Roughly instructions are below:

  1. Create canvas with extending the vertical length
  2. Put the rotated image onto the bottom of this canvas
  3. Put the original image onto the top of this canvas

Sample of concrete implementation is below:
require 'mini_magick'

original_file = "original.jpg"

image_cloned = MiniMagick::Image.open(original_file)

background_color = 'black' # set background color
COMPOSITE_GRAVITY = 'north'
TRANSPARENCY = '65%'
REFLECTION_FACTOR = Math.sqrt(2)

image_cloned.combine_options do |mogrify|
  mogrify.flip
  mogrify.fill background_color
  mogrify.colorize TRANSPARENCY
end

image_original = MiniMagick::Image.open(original_file)

image_cloned.combine_options(:convert) do |convert|
  new_width = image_original[:width]
  new_height = (image_original[:height]*REFLECTION_FACTOR).to_i
  convert.size "#{new_width}x#{new_height}"
  convert.xc background_color
  convert.swap '0,1'
  convert.gravity COMPOSITE_GRAVITY
  convert.geometry "+0+#{image_original[:height]}"
  convert.composite
end

image_combined = image_cloned.composite(image_original) do |c|
  c.gravity COMPOSITE_GRAVITY
end

output_file = "reflected_#{background_color}.jpg"
image_combined.write output_file
puts "#{output_file} is generated."

These are the output samples.

for white background:

for black background:

Tuesday, February 7, 2012

specular reflection with mini_magick (1)

"Specular Reflection" - a.k.a. "mirror effect" - is the most popular effect for image file to be good-looking. This effect consists of 4 operations.
  1. clone from original image and rotate it
  2. add transparency to cloned image
  3. combine original image and cloned one
  4. resize combined image
In this article, I introduce the operation of both (1) and (2) with referring ImageMagick's sample page and using mini_magick.

This ruby script is like below:
require 'mini_magick'

image_original = MiniMagick::Image.open("original.jpg")

image_cloned = image_original.clone

image_cloned.combine_options do |c|
  c.flip
  c.fill 'white' # set background color
  c.colorize '65%'
end

image_cloned.write "cloned_rotate_transparent.jpg"

You can change the argument(color name) of fill method depending on the background color where you want to put the image file onto. These are original image and rotated and transparent one.


(continue to phosphorescence: specular reflection with mini_magick (2))

Saturday, February 4, 2012

JRuby 1.7 becomes 1.9 mode as default mode

In this issue ticket - http://jira.codehaus.org/browse/JRUBY-6387 - JRuby team surveys that JRuby 1.7 becomes 1.9 mode as default mode or not. And then, decided!!