SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Thursday, March 5, 2009

Ruby program to crop an image using rmagick

Cropping an image in ruby,then we have to proceed via rmagick.At first install imagemagick and rmagick gem into your system.

Whenever we want to do something with ruby then at first we have work it out in irb console

Before proceeding for the crop we have to get the width,height and x,y co-ordinates of the image.



For cropping the image we have to use the instance method Crop

img.crop(x, y, width, height) -> image
img.crop(gravity, x, y, width, height) -> image
img.crop(gravity, width, height) -> image



#!/usr/bin/ruby -w
require 'rubygems'
require 'rmagick'
include Magick
image=Image.read("/home/Mac/Desktop/flowers.jpg").first
face=image.crop!(270,55,194,194)
face.write("/home/Mac/Desktop/crop.jpg")


Note*: This Program tested and works in all Linux system.