Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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, ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top