Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Completed get_pixel correctly

  • Loading branch information...
commit 194009e8b6fab89636383ea7a9f296fd8511695d 1 parent 8009598
@aseldawy authored
View
17 README
@@ -66,7 +66,7 @@ Actually, I didn't need this feature, but I may need it in the future.
At this point I decided to make my own gem and QuickMagick was born.
I addressed the problems of MiniMagick while using the same main idea.
-First, QuickMagick doesn't write any temporary images to disk.
+First, QuickMagick doesn't write any temporary image files to disk.
It doesn't issue any command line commands till the very end when you are saving the image.
Second, I made an API similar to RMagick which allows for accessing multipage images.
Third, I added API commands to create images from scratch and drawing simple primitives on images.
@@ -107,9 +107,9 @@ I couldn't test MiniMagick for this because it doesn't support an API for drawin
== Conclusion
QuickMagick is very easy to install, very easy to use and allows you to access most features of ImageMagick.
-RMagick is a bit faster and has an advantage of allowing you to access single pixels but it's a bit hard to install.
+RMagick is a bit faster but it's a bit hard to install.
Also RMagick sometimes fail when it tries to handle large images.
-MiniMagick is proved to be a bit slower than QuickMagick with no advantage.
+MiniMagick is proved to be slower than QuickMagick with no advantage.
So, it's better to use QuickMagick when your application is not image-centric.
This means, you're not going to build an image manipulation tool or something like this.
For normal operations like resize, rotate, generating captchas ... etc, QuickMagick will be a good friend of you.
@@ -161,7 +161,7 @@ QuickMagick supports also ImageList s
il.resize "300x300>"
il.save!
-(new) You can also create images from scratch
+You can also create images from scratch
# Create a 300x300 gradient image from yellow to red
i1 = QuickMagick::Image::gradient(300, 300, QuickMagick::RadialGradient, :yellow, :red)
i1.save 'gradient.png'
@@ -178,6 +178,15 @@ QuickMagick supports also ImageList s
... you can then convert it to blob using
i.to_blob
+
+(new) You can now access single pixels using QuickMagick
+ # Create a 300x300 gradient image from yellow to red
+ i1 = QuickMagick::Image::gradient(300, 300, QuickMagick::RadialGradient, :yellow, :red)
+ i1.save 'gradient.png'
+
+ # Now you can access single pixel values
+ i1.get_pixel(10,10) # [255, 0, 0]
+ i1.get_pixel(50,50) # [255, 15, 0]
For more information on drawing API visit:
http://www.imagemagick.org/Usage/draw/
View
2  Rakefile
@@ -2,7 +2,7 @@ require 'rubygems'
require 'rake'
require 'echoe'
-Echoe.new('quick_magick', '0.6.2') do |p|
+Echoe.new('quick_magick', '0.7.0') do |p|
p.description = "QuickMagick allows you to access ImageMagick command line functions using Ruby interface."
p.url = "http://quickmagick.rubyforge.org/"
p.author = "Ahmed ElDawy"
View
21 lib/quick_magick/image.rb
@@ -19,12 +19,8 @@ def read(filename, &proc)
info = identify(%Q<"#{filename}">)
info_lines = info.split(/[\r\n]/)
images = []
- if info_lines.size == 1
- images << Image.new(filename, info_lines.first)
- else
- info_lines.each_with_index do |info_line, i|
- images << Image.new("#{filename}[#{i.to_s}]", info_line)
- end
+ info_lines.each_with_index do |info_line, i|
+ images << Image.new("#{filename}", i, info_line)
end
images.each(&proc) if block_given?
return images
@@ -38,7 +34,7 @@ def gradient(width, height, type=QuickMagick::LinearGradient, color1=nil, color2
template_name = type + ":"
template_name << color1.to_s if color1
template_name << '-' << color2.to_s if color2
- i = self.new(template_name, nil, true)
+ i = self.new(template_name, 0, nil, true)
i.size = QuickMagick::geometry(width, height)
i
end
@@ -47,7 +43,7 @@ def gradient(width, height, type=QuickMagick::LinearGradient, color1=nil, color2
def solid(width, height, color=nil)
template_name = QuickMagick::SolidColor+":"
template_name << color.to_s if color
- i = self.new(template_name, nil, true)
+ i = self.new(template_name, 0, nil, true)
i.size = QuickMagick::geometry(width, height)
i
end
@@ -56,7 +52,7 @@ def solid(width, height, color=nil)
def pattern(width, height, pattern)
raise QuickMagick::QuickMagickError, "Invalid pattern '#{pattern.to_s}'" unless QuickMagick::Patterns.include?(pattern.to_s)
template_name = "pattern:#{pattern.to_s}"
- i = self.new(template_name, nil, true)
+ i = self.new(template_name, 0, nil, true)
i.size = QuickMagick::geometry(width, height)
i
end
@@ -210,8 +206,9 @@ def antialias=(flag)
alias original_filename image_filename
# constructor
- def initialize(filename, info_line=nil, pseudo_image=false)
+ def initialize(filename, index=0, info_line=nil, pseudo_image=false)
@image_filename = filename
+ @index = index
@pseudo_image = pseudo_image
if info_line
@image_infoline = info_line.split
@@ -222,7 +219,7 @@ def initialize(filename, info_line=nil, pseudo_image=false)
# The command line so far that will be used to convert or save the image
def command_line
- %Q< "(" #{@arguments} #{QuickMagick::c image_filename} ")" >
+ %Q< "(" #{@arguments} #{QuickMagick::c(image_filename + (@pseudo_image ? "" : "[#{@index}]"))} ")" >
end
# An information line about the image obtained using 'identify' command line
@@ -482,7 +479,7 @@ def size
# It is not recommended at all to use this method for image processing for example.
def get_pixel(x, y)
error_file = Tempfile.new('identify_error')
- result = `identify -verbose #{QuickMagick::c(image_filename+"[1x1+#{x}+#{y}]")} 2>'#{error_file.path}'`
+ result = `identify -verbose -crop #{QuickMagick::geometry(1,1,x,y)} #{QuickMagick::c(image_filename)}[#{@index}] 2>'#{error_file.path}'`
unless $?.success?
error_message = <<-ERROR
Error executing command: identify #{image_filename}
View
4 quick_magick.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{quick_magick}
- s.version = "0.6.2"
+ s.version = "0.7.0"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Ahmed ElDawy"]
- s.date = %q{2009-10-25}
+ s.date = %q{2009-11-16}
s.description = %q{QuickMagick allows you to access ImageMagick command line functions using Ruby interface.}
s.email = %q{ahmed.eldawy@badrit.com}
s.extra_rdoc_files = ["README", "lib/quick_magick.rb", "lib/quick_magick/image.rb", "lib/quick_magick/image_list.rb"]
Please sign in to comment.
Something went wrong with that request. Please try again.