1

I have an image that is 100 X 100, and want to center it in a blank white image that is 200 X 200.

How would I do so with ImageScience and Ruby, or another third party package? And without ImageMagick nor FreeImage? I know that's very constraining but those 2 are being rather lame to me as both don't work on my local Mac and my EngineYard Amazon instance. I am able to use FreeType with Ruby on my Mac, but it fails to deploy on Amazon cloud. I can't install RMagick on my Mac, but it can install on my Amazon cloud.

As an aside, I feel ImageMagick should be installed automatically in every Linux and Mac machine. Would save some people lots of trouble. So much pain for so little value.

Henley
  • 21,258
  • 32
  • 119
  • 207

2 Answers2

8

The best way would be to use a pure ruby library, such as http://docs.seattlerb.org/png/ from Seattle.rb or https://github.com/wvanbergen/chunky_png

It's quite easy to follow. You should create a white 200x200 canvas and load your image onto it, or if you find it easier, compose images using alpha blending.

(from chucky's examples):

# Compose images using alpha blending.
avatar = ChunkyPNG::Image.from_file('avatar.png')
badge  = ChunkyPNG::Image.from_file('no_ie_badge.png')
avatar.compose!(badge, 10, 10)
avatar.save('composited.png', :fast_rgba) # Force the fast saving routine.

If you don't really need a new image and it's only for displaying pourposes, using css and/or javascript would be much easier.

fuzzyalej
  • 5,903
  • 2
  • 31
  • 49
  • 1
    Thank you so much! This is what I was looking for!!! WOOT! I thought I was gonna have to go thru ImageMagick. Haha – Henley Jan 19 '12 at 22:07
0

Sidestepping the question maybe, but did you try installing ImageMagick on your Mac through Homebrew? This is as simple as just installing Homebrew and typing one command:

brew install imagemagick

This should work without any problems at all. Homebrew is like the package manager that should have been included by default in Mac OS X. I also use it to install other packages not included by default, like Git, Ack, Graphviz, ...

Tom De Leu
  • 8,144
  • 4
  • 31
  • 30
  • @mika: see text in the question: "I know that's very constraining but those 2 are being rather lame to me as both don't work on my local Mac". Seems to me the questioner didn't know about Homebrew, tried to install ImageMagick some other way and failed. With Homebrew however, it's very very easy. Seems that the questioner even preferred ImageMagick as he says "I feel ImageMagick should be installed automatically in every Linux and Mac machine". – Tom De Leu Mar 27 '14 at 08:05
  • you're right! But it won't let me upvote you back without an answer edit :-/ – mika Mar 30 '14 at 15:25