image_merger.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'rmagick'
  2. include Magick
  3. def append_image(image1_in, images2_in, image_out)
  4. i = Magick::ImageList.new
  5. i = Magick::ImageList.new(image1_in,images2_in)
  6. u = i.append(true);
  7. u.write('images/Type Double.png');
  8. end
  9. def crop_image()
  10. images = ['images/Type Bug.png', 'images/Type Dark.png', 'images/Type Dark - Copy.png']
  11. img = Magick::Image.read(images[0]).first # path of Orignal image that has to be worked upon
  12. puts img.inspect
  13. def try(x,y,width,height)
  14. images = ['images/Type Bug.png', 'images/Type Dark.png', 'images/Type Dark - Copy.png']
  15. # converting x,y , width and height to integer values in next four statements
  16. x= x.to_i
  17. y= y.to_i
  18. width= width.to_i
  19. height= height.to_i
  20. # Demonstrate the Image#crop method
  21. @st = images[0] # path of image written after changing size or not changing also
  22. img = Magick::Image.read(@st)[0]
  23. # Crop the specified rectangle out of the img.
  24. chopped = img.crop(x, y, width,height)
  25. # Go back to the original and highlight the area
  26. # corresponding to the retained rectangle.
  27. rect = Magick::Draw.new
  28. rect.stroke('transparent')
  29. rect.fill('black')
  30. rect.fill_opacity(1.0)
  31. rect.rectangle(x, y, 100+x, 10+y)
  32. rect.draw(img)
  33. img.write(images[1]) #path of image written before cropping
  34. # Create a image to use as a background for
  35. # the “after” image.
  36. bg = Magick::Image.new(img.columns, img.rows)
  37. # Composite the the “after” (chopped) image on the background
  38. bg = bg.composite(chopped, 38,81, Magick::OverCompositeOp)
  39. bg.write(images[2]) # path of image written after cropping the desired part
  40. exit
  41. end
  42. try(100, 50, 150, 100)
  43. end