Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Integrate with Subexec gem to run commands, refactor/clean up lots

  • Loading branch information...
commit b4ef6723dea45da857e3e55085570370e56870df 1 parent 70c41b4
Peter Kieltyka authored
View
4 README.rdoc
@@ -1,6 +1,6 @@
= MiniMagick
-A ruby wrapper for ImageMagick command line.
+A ruby wrapper for ImageMagick or GraphicsMagick command line.
== Why?
@@ -69,4 +69,4 @@ http://www.imagemagick.org/script/command-line-options.php#format
== Requirements
-You must have ImageMagick installed.
+You must have ImageMagick or GraphicsMagick installed.
View
19 Rakefile
@@ -1,6 +1,7 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
+require 'rake/gempackagetask'
$:.unshift(File.dirname(__FILE__) + "/lib")
require 'mini_magick'
@@ -10,7 +11,7 @@ task :default => :test
desc 'Test the mini_magick plugin.'
Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
+ t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
@@ -25,15 +26,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gemspec|
- gemspec.name = "mini_magick"
- gemspec.summary = "Manipulate images with minimal use of memory."
- gemspec.email = "probablycorey@gmail.com"
- gemspec.homepage = "http://github.com/pkieltyka/mini_magick"
- gemspec.authors = ["Corey Johnson", "Peter Kieltyka"]
- end
-rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
-end
+spec = eval(File.read('mini_magick.gemspec'))
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+end
View
2  VERSION
@@ -1 +1 @@
-1.2.6
+1.3.0
View
26 lib/mini_magick.rb
@@ -1,12 +1,10 @@
-require "open-uri"
-require "stringio"
-require "fileutils"
-require "open3"
-require "tempfile"
+require 'tempfile'
+require 'subexec'
module MiniMagick
class << self
attr_accessor :processor
+ attr_accessor :timeout
end
class MiniMagickError < RuntimeError; end
@@ -87,14 +85,14 @@ def format(format, page=0)
run_command("mogrify", "-format", format, @path)
old_path = @path.dup
- @path.sub!(/(\.\w+)?$/, ".#{format}")
+ @path.sub!(/(\.\w*)?$/, ".#{format}")
File.delete(old_path) unless old_path == @path
unless File.exists?(@path)
begin
FileUtils.copy_file(@path.sub(".#{format}", "-#{page}.#{format}"), @path)
- rescue e
- raise MiniMagickError, "Unable to format to #{format}; #{e}" unless File.exist?(@path)
+ rescue => ex
+ raise MiniMagickError, "Unable to format to #{format}; #{ex}" unless File.exist?(@path)
end
end
ensure
@@ -160,14 +158,14 @@ def run_command(command, *args)
end
command = "#{MiniMagick.processor} #{command} #{args.join(' ')}".strip
- # $stderr.puts "=====> #{command}"
+ $stderr.puts "=====> #{command}"
- output = `#{command} 2>&1`
-
- if $?.exitstatus != 0
- raise MiniMagickError, "ImageMagick command (#{command.inspect}) failed: #{{:status_code => $?, :output => output}.inspect}"
+ sub = Subexec.run(command, :timeout => MiniMagick.timeout)
+
+ if sub.exitstatus != 0
+ raise MiniMagickError, "MiniMagick command (#{command.inspect}) failed: #{{:status_code => sub.exitstatus, :output => sub.output}.inspect}"
else
- output
+ sub.output
end
end
end
View
68 mini_magick.gemspec
@@ -1,57 +1,19 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
-# -*- encoding: utf-8 -*-
+version = File.read("VERSION").strip
Gem::Specification.new do |s|
- s.name = %q{mini_magick}
- s.version = "1.2.6"
+ s.name = 'mini_magick'
+ s.version = version
+ s.platform = Gem::Platform::RUBY
+ s.summary = "Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick"
+ s.description = "Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick"
+
+ s.authors = ["Corey Johnson", "Peter Kieltyka"]
+ s.email = ["probablycorey@gmail.com", "peter@nulayer.com"]
+ s.homepage = "http://github.com/nulayer/mini_magick"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Corey Johnson", "Peter Kieltyka"]
- s.date = %q{2010-03-15}
- s.email = %q{probablycorey@gmail.com}
- s.extra_rdoc_files = [
- "README.rdoc"
- ]
- s.files = [
- ".gitignore",
- "MIT-LICENSE",
- "README.rdoc",
- "Rakefile",
- "VERSION",
- "lib/mini_gmagick.rb",
- "lib/mini_magick.rb",
- "test/actually_a_gif.jpg",
- "test/animation.gif",
- "test/command_builder_test.rb",
- "test/image_temp_file_test.rb",
- "test/image_test.rb",
- "test/leaves.tiff",
- "test/not_an_image.php",
- "test/simple-minus.gif",
- "test/simple.gif",
- "test/trogdor.jpg"
- ]
- s.homepage = %q{http://github.com/pkieltyka/mini_magick}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
- s.summary = %q{Manipulate images with minimal use of memory.}
- s.test_files = [
- "test/command_builder_test.rb",
- "test/image_temp_file_test.rb",
- "test/image_test.rb"
- ]
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
+ s.files = Dir['README.rdoc', 'VERSION', 'MIT-LICENSE', 'Rakefile', 'lib/**/*']
+ s.test_files = Dir['test/**/*']
+ s.require_path = 'lib'
+
+ s.add_runtime_dependency('subexec')
end
-
View
17 test/image_temp_file_test.rb
@@ -1,17 +0,0 @@
-require 'test/unit'
-require File.join(File.dirname(__FILE__), '../lib/image_temp_file')
-
-class ImageTempFileTest < Test::Unit::TestCase
- include MiniMagick
-
- def test_multiple_calls_yield_different_files
- first = ImageTempFile.new('test')
- second = ImageTempFile.new('test')
- assert_not_equal first.path, second.path
- end
-
- def test_temp_file_has_given_extension
- assert_match /^[^.]+\.jpg$/, ImageTempFile.new('jpg').path
- assert_match /^[^.]+\.png$/, ImageTempFile.new('png').path
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.