Archive for August, 2008|Monthly archive page

Ruby and Rails Tutorials

I am giving url of sites that are either books , tutorials or simply a help in form of video , audio and refcards to learn Ruby and Rails.

Ruby :

Online Guide : The Pragmatic Programmers Guide (Picaxe Guide)

Site-point

Book : The Ruby Cookbook

Ruby Learning through flashcards : YoYoBrain

Online Tutorial : Meshplex Tutorial

Rails : In this section I have been able to find video tutorials only .

Video tutorial : Learning Rails

Video Tutorial : Railscasts

PS : I will try to update the list if I am able to find other good tutorials . Otherwise , there are very good books available in the market which help the cause of learning ruby and rails and I will try to name a few which I know in one of my following posts

Enjoy Learning !!! :D

Ruby program to scale and crop an Image using Rmagick


#!/usr/local/bin/ruby -w
require ‘RMagick’
include Magick

img = Magick::Image.read(‘/home/anmol/jack.jpg’).first # path of Orignal image that has to be worked upon
puts img.inspect

def try(x,y,width,height)


# converting x,y , width and height to integer values in next four statements
x= x.to_i
y= y.to_i
width= width.to_i
height= height.to_i

# Demonstrate the Image#crop method
@st = ‘/home/anmol/tempimage.jpg’ # path of image written after changing size or not changing also
img = Magick::Image.read(@st)[0]

# Crop the specified rectangle out of the img.
chopped = img.crop(x, y, width,height)

# Go back to the original and highlight the area
# corresponding to the retained rectangle.
rect = Magick::Draw.new
rect.stroke(‘transparent’)
rect.fill(‘black’)
rect.fill_opacity(1.0)
rect.rectangle(x, y, 100+x, 10+y)
rect.draw(img)

img.write(‘/home/anmol/imgbeforecrop.jpg’) #path of image written before cropping

# Create a image to use as a background for
# the “after” image.
bg = Magick::Image.new(img.columns, img.rows)

# Composite the the “after” (chopped) image on the background
bg = bg.composite(chopped, 38,81, Magick::OverCompositeOp)

bg.write(‘/home/anmol/imgaftercrop.jpg’) # path of image written after cropping the desired part

exit

end

puts “Please enter ::
1 = Making image one-fourth of it’s orignal size
2 = Making image half of it’s orignal size
3 = Making image three-fourth of it’s orignal size
4 = Minfing the image
5 = Magnfing the image \n”

print “option selected = ” ; option = gets
option = option.to_i

puts “Please enter x co=ordinate , y co-ordinate , width and height from x and y co-ordinates of the portion that is to be cropped [ALL THE FOUR VALUES TO BE NUMERIC VALUES AND GREATER THAN ZERO] “

print “x co-ordinate ” ; xc= gets ;
print “y co-ordinate ” ; yc= gets ;
print “width ” ; w= gets ;
print “height ” ; h= gets ;

case option
when 1
thumb = img.scale(0.25) #scale image to 25 % of it’s orignal size
thumb.write “/home/anmol/tempimage.jpg”
# path of image written after changing size or not changing also
puts thumb.inspect
try(xc,yc,w,h)

when 2
thumb = img.scale(0.50) #scale image to 50 % of it’s orignal size
thumb.write “/home/anmol/tempimage.jpg”
# path of image written after changing size or not changing also
puts thumb.inspect
try(xc,yc,w,h)

when 3
thumb = img.scale(0.75) #scale image to 75 % of it’s orignal size
thumb.write “/home/anmol/tempimage.jpg”
# path of image written after changing size or not changing also
puts thumb.inspect
try(xc,yc,w,h)

when 4
thumb = img.minify # minify the image
thumb.write “/home/anmol/tempimage.jpg”
# path of image written after changing size or not changing also
puts thumb.inspect
try(xc,yc,w,h)

when 5
thumb = img.magnify #magnify the image
thumb.write “/home/anmol/tempimage.jpg”
# path of image written after changing size or not changing also
try(xc,yc,w,h)

else
puts “the image will remain in it’s orignal size “
thumb = img
thumb.write “/home/anmol/tempimage.jpg” # path of image written after changing size or not changing also
try(xc,yc,w,h)

end

I said in the last post that I am working on Simple Picture editor for Skid software , So I have posted a liitle bit of code which I have written in Ruby , it’s a small step and a lot has to be done .

This program first asks user weather he/she wants to change the size of the image to one-fourth of it’s orignal size , minify it , magnify it etc . After you specify the size , user is asked about the dimension of the rectangle which is to be cropped from the image . After specifing the rectangle dimension , the image cropped image is written .The program produces 3 images , first image is tempimage.jpg which is created if user agrees to change the size of the image ; second image is imgbeforecrop.jpg which specifies the rectanglular portion in the image which will cropped by blackening that particular portion of the image ; third image is the imgaftercrop.jpg which has only the cropped portion of the image.

This program is not complete yet and lot of work has to be done on it . First thing which I want to do is to incorporate a graph or grid with the picture so that it becomes easier for the user to specify the crop portion otherwise it is a relatively tough task to do .

Other thing is that I want to get the path of the image file from User , but somehow Image.read function doesn’t take User input , so I will try find some other way .

I will subsequently post the newer versions of the program , as soon as I do some work on it that is worth mentioning :D

PS:: Please don’t forget to change the path of the image , the path of thumb.write (in case statement) and path of @st in try function should match .

Please Install Rmagick and Ruby prior to run the program .

This program was run on Linux and for Windows commands can be slightly different .

Web Programming Lecture in Second Life

On 10 August 2008 , I ,Anmolanand Inshan*, got an oppertunity to attend a Live lecture on Web Programming through Ruby and Ruby on Rails in my Second Life . The lecture was delivered by Professor Arun Nighfire* (Arun Mehta) at the Kaosome hub . Apart from me other people who attended the lecture were Al Supercharge* , Freemason Magic* and Pechkin Lavochkin*. Both Al and Freemason were familiar with web programming , Al knows PHP and Freemason knows LSL i.e Linden Scripting Language . Pechkin Lavochkin is a SOMA Intern and Site Manager.

Basically , Professor Mehta told us about the beauty and simplicity of Ruby and Ruby on Rails . He also showed us his framework Skid (Special Kid) which has been designed for Special children(example : those with Cerebral Palasy , Autism etc ) to help them to communicate easily and help them to come into the mainframe of the life .

One of the things which I noticed when I was hearing to the lecture was that there was an amplification in the voice when I went towards Professor Mehta .

So , this lecture was aimed to give an Insight into Ruby , RoR and Skid , so that people can learn Ruby and RoR and also help in making new modules for Skid , if they want .

I am making a module which will help children with simple Picture editing . :)

The next lecture is scheduled for 17 August 2008 , 2230 hrs by IST and round about 10 am by Second life time . You can check the Second Life Events for correct timings and Venue as there can be a change .

To know more about Second Life , click here

* Names in Second Life

Presentation on Software Engineering

Today there was a workshop on “Software Engineering and it’s Principles ” in my college i.e. Acharya Narendra Dev of Delhi University . I was one of the resource persons along with my friends . I gave a presentation on “Introduction to Software Engineering and Software Engineering Models” .

The workshop was aimed to give PGDCA (Post Graduate Diploma in Computer Applications ) students basic knowledge about Software Engineering and it’s underlying Principles . It was a huge opertunity for me because I am an Undergradute and teaching students of Post Graduation something is big honour.

I started my presentation by giving them a simple definition that software engineering means applying engineering concepts to develop a software .

Next I told them the reasons that ” why we study software engineering?? ” and ” why software engineering was introduced ?? “

The next thing on which I talked about was Software Process Models ; in this section I tried to throw light on Waterfall Model , Prototyping Model and Spial Model . Basically I told them about the methodology that is adopted in each model , Pros and Cons of respective model and lastly the areas where these can applied and best performance can be achieved out of the software engineering process .

I enjoyed teaching and it helped me too as my concepts of software engineering became more clear !!! :)