Giter Club home page Giter Club logo

imageruby's Introduction

= ImageRuby - flexible ruby gem for image processing

ImageRuby is a gem for image processing written in pure ruby, this makes the library very portable and easy to install

Also, the gem was desgined to accept extensions like:
 * new format decoders made from scratch (Ruby or C)
 * new format decoders based on existent C libraries like libpng, libbmp, etc...
 * new image operations (Ruby or C)
 * re-implementations of parts in C to improve performance on environments where it is possible

== Installation

=== Gem installation

sudo gem install imageruby

== Documentation

Full API documentation can be found on:
http://tario.github.com/imageruby/doc/

== Examples

NOTE: Examples loads and saves bitmap files, imageruby-bmp gem must be installed in order
to get the examples work

=== Create and save a black image

  require "rubygems"
  require "imageruby"

  include ImageRuby

  #  creates an image of 150x150 pixels filled with black
  image = ImageRuby::Image.new(150,150, Color.black)

  begin
  # this only work if imageruby-bmp gem is installed
  image.save("black.bmp", :bmp)
  rescue
    print "Error while trying to save, you must install imageruby-bmp gem"
  end

=== Create an image with vertical stripes filled with default named colors

  require "rubygems"
  require "imageruby"

  include ImageRuby

  print "list of named colors:\n"
  print "--------------------------\n"

  colors = Array.new

  Color.named_colors.each do |name, color|
	print "#{name}: #{color.inspect}\n"
	colors << color
  end

  image = Image.new( colors.count * 32, 512)

  x = 0
  colors.each do |color|
  image[x..x+31, 0..511] = Image.new(32,512,color)
  x = x + 32
  end

  image.save("colors.bmp", :bmp)

=== Gradient using block parameter

  require "rubygems"
  require "imageruby"

  include ImageRuby

  gradient_images = Array.new

  gradient_images << Image.new(64,64) {|x,y| 
    Color.from_rgb(x*4,y*4,0) 
  }

  gradient_images << Image.new(64,64) {|x,y| 
    Color.from_rgb(0,x*4,y*4) 
  }

  gradient_images << Image.new(64,64) {|x,y| 
    Color.from_rgb(y*4,0,x*4) 
  }

  (0..gradient_images.count-1).each do |i|
	gradient_images[i].save("gradient#{i}.bmp", :bmp)
  end

  all_gradient = Image.new(96*gradient_images.count, 96)

  (0..gradient_images.count-1).each do |i|
	all_gradient.draw!(i*96+16, 16, gradient_images[i])
  end

  all_gradient.save("gradients.bmp", :bmp)


=== Draw with mask

  require "rubygems"
  require "imageruby"

  include ImageRuby

  colors = Image.from_file("colors.bmp")
  gradients = Image.from_file("gradients.bmp")

  without_mask = colors.draw(128,192,gradients)
  without_mask.save("without_mask.bmp", :bmp)

  with_mask = colors.draw(128,192,gradients.mask(Color.black))
  with_mask.save("with_mask.bmp", :bmp)

=== Draw with transparency effects

  require "rubygems"
  require "imageruby"

  include ImageRuby

  colors = Image.from_file("colors.bmp")
  gradients = Image.from_file("gradients.bmp")

  transparent_black = Color.black
  transparent_black.a = 128


  colors.draw(128,192,gradients.color_replace(Color.black, transparent_black)).save("sample1.bmp", :bmp)

  half_transparent = gradients.map_pixel{ |x,y,c|
	c.a = 128 if x >144
	c
  }
  colors.draw(128,192,half_transparent).save("sample2.bmp", :bmp)



== Copying

Copyright (c) 2011 Dario Seminara, released under the GPL License (see LICENSE)

imageruby's People

Contributors

tario avatar

Stargazers

 avatar Daniel Senff avatar  avatar Hacker Labs avatar Victor Hugo Bernardes de Souza avatar Bernardo Simoes avatar Jean Pierre avatar Toshiyuki Hirooka avatar Amer Jazaerli avatar Junfeng Liu avatar Gustavo avatar  avatar  avatar Matthew Rothenberg avatar Ivan Storck avatar Jason Torres avatar

Watchers

 avatar

Forkers

amadanmath

imageruby's Issues

Error when trying to run examples

$ ruby gradient.rb
/home/railsdev1/.rvm/gems/ruby-1.9.3-p385@default/gems/imageruby-0.2.3/lib/imageruby/pureruby.rb:156:in <': comparison of String with 255 failed (ArgumentError) from /home/railsdev1/.rvm/gems/ruby-1.9.3-p385@default/gems/imageruby-0.2.3/lib/imageruby/pureruby.rb:156:inblock (2 levels) in draw!'
from /home/railsdev1/.rvm/gems/ruby-1.9.3-p385@default/gems/imageruby-0.2.3/lib/imageruby/pureruby.rb:151:in each' from /home/railsdev1/.rvm/gems/ruby-1.9.3-p385@default/gems/imageruby-0.2.3/lib/imageruby/pureruby.rb:151:inblock in draw!'
from /home/railsdev1/.rvm/gems/ruby-1.9.3-p385@default/gems/imageruby-0.2.3/lib/imageruby/pureruby.rb:145:in each' from /home/railsdev1/.rvm/gems/ruby-1.9.3-p385@default/gems/imageruby-0.2.3/lib/imageruby/pureruby.rb:145:indraw!'
from gradient.rb:27:in block in <main>' from gradient.rb:26:ineach'
from gradient.rb:26:in `

'

text to image and image compositing?

This project is very exciting to me, as I maintain a popular gem called lolcommits which I would love to move off using RMagick/ImageMagick, as the vast majority of the installation problems people have come from trying to get IM installed and working, so a pure Ruby/gem solution would be ideal.

Are there any plans on the roadmap to add image compositing or font to image capabilities to imageruby?

( had been tracking this on my side at lolcommits/lolcommits#24 )

scaling down a jpg or png

Hi,

I've been trying to find a ruby gem which I can use to resize images and that won't require the user to install any additional software.

Is it possible to do it with imageruby?

UTF-8 Encoding strange error

This code fails:

require 'ImageRuby'
include ImageRuby

activeSprite = Image.new(12,12, Color.blue)
img = Image.new(128, 12, Color.coerce("#a8a8a8"))
img.draw!(0,0, activeSprite)

Backtrace:

ArgumentError: invalid byte sequence in UTF-8
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:154:in `ord'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:154:in `block (2 levels) in draw!'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:151:in `each'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:151:in `block in draw!'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:145:in `each'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:145:in `draw!'
from (irb):5
from /usr/local/bin/irb:12:in `<main>

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.