miso 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,11 @@ module Miso
44
44
  self
45
45
  end
46
46
 
47
+ def auto_orient
48
+ @operations << [:auto_orient, []]
49
+ self
50
+ end
51
+
47
52
  def apply(input_file, output_file)
48
53
  image = Image.new(input_file, @processor_class)
49
54
  @operations.each { |method, args| image.send(method, *args) }
@@ -19,6 +19,11 @@ module Miso
19
19
  return self
20
20
  end
21
21
 
22
+ def auto_orient
23
+ @processor.auto_orient
24
+ return self
25
+ end
26
+
22
27
  def dimensions
23
28
  @processor.dimensions
24
29
  end
@@ -52,6 +57,10 @@ module Miso
52
57
  new(input_file, processor_class).fit(width, height).write(output_file)
53
58
  end
54
59
 
60
+ def self.auto_orient(input_file, output_file, processor_class = nil)
61
+ new(input_file, processor_class).auto_orient.write(output_file)
62
+ end
63
+
55
64
  def self.dimensions(input_file, processor_class = nil)
56
65
  new(input_file, processor_class).dimensions
57
66
  end
@@ -50,6 +50,10 @@ module Miso
50
50
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #fit."
51
51
  end
52
52
 
53
+ def auto_orient
54
+ raise NotImplementedError, "The class `#{self.class.name}' does not implement #auto_orient."
55
+ end
56
+
53
57
  def dimensions
54
58
  raise NotImplementedError, "The class `#{self.class.name}' does not implement #dimensions."
55
59
  end
@@ -22,6 +22,10 @@ module Miso
22
22
  operations << "-resize #{width}x#{height}"
23
23
  end
24
24
 
25
+ def auto_orient
26
+ operations << "-auto-orient"
27
+ end
28
+
25
29
  def dimensions
26
30
  if info = identify(input_file) and match = /\s(\d+)x(\d+)\+/.match(info)
27
31
  match.to_a[1..2].map { |d| d.to_i }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miso
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eloy Duran
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-17 00:00:00 +02:00
19
+ date: 2011-10-26 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -50,9 +50,6 @@ extra_rdoc_files:
50
50
  files:
51
51
  - LICENSE
52
52
  - README
53
- - Rakefile
54
- - TODO
55
- - VERSION
56
53
  - lib/miso.rb
57
54
  - lib/miso/factory.rb
58
55
  - lib/miso/image.rb
@@ -60,24 +57,14 @@ files:
60
57
  - lib/miso/processor/core_image.rb
61
58
  - lib/miso/processor/graphics_magick.rb
62
59
  - lib/miso/processor/image_magick.rb
63
- - miso.gemspec
64
- - spec/api/factory_spec.rb
65
- - spec/api/image_spec.rb
66
- - spec/api/processor_spec.rb
67
- - spec/api/processors_spec.rb
68
- - spec/fixtures/120x100.png
69
- - spec/functional/processor/core_image_spec.rb
70
- - spec/functional/processor/graphics_magick_spec.rb
71
- - spec/functional/processor/image_magick_spec.rb
72
- - spec/functional/processor_spec.rb
73
- - spec/start.rb
60
+ - TODO
74
61
  has_rdoc: true
75
62
  homepage: http://github.com/Fingertips/miso
76
63
  licenses: []
77
64
 
78
65
  post_install_message:
79
- rdoc_options:
80
- - --charset=UTF-8
66
+ rdoc_options: []
67
+
81
68
  require_paths:
82
69
  - lib
83
70
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -101,17 +88,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
88
  requirements: []
102
89
 
103
90
  rubyforge_project:
104
- rubygems_version: 1.3.7
91
+ rubygems_version: 1.6.2
105
92
  signing_key:
106
93
  specification_version: 3
107
94
  summary: Miso is a unified API for simple image operations commonly used on the web.
108
- test_files:
109
- - spec/api/factory_spec.rb
110
- - spec/api/image_spec.rb
111
- - spec/api/processor_spec.rb
112
- - spec/api/processors_spec.rb
113
- - spec/functional/processor/core_image_spec.rb
114
- - spec/functional/processor/graphics_magick_spec.rb
115
- - spec/functional/processor/image_magick_spec.rb
116
- - spec/functional/processor_spec.rb
117
- - spec/start.rb
95
+ test_files: []
96
+
data/Rakefile DELETED
@@ -1,56 +0,0 @@
1
- require 'rubygems'
2
- require 'rake/rdoctask'
3
-
4
- desc "Run all specs by default"
5
- task :default => :spec
6
-
7
- namespace :spec do
8
- desc "Run all API specs"
9
- task :api do
10
- Dir[File.dirname(__FILE__) + '/spec/api/**/*_spec.rb'].each do |file|
11
- load file
12
- end
13
- end
14
-
15
- desc "Run all functional specs"
16
- task :functional do
17
- Dir[File.dirname(__FILE__) + '/spec/functional/*_spec.rb'].each do |file|
18
- load file
19
- end
20
- end
21
- end
22
-
23
- desc "Run all specs"
24
- task :spec do
25
- sh "ruby -r #{Dir.glob('spec/**/*_spec.rb').join(' -r ')} -e ''"
26
- end
27
-
28
- namespace :docs do
29
- Rake::RDocTask.new(:generate) do |rd|
30
- rd.main = "README"
31
- rd.rdoc_files.include("README", "LICENSE", "lib/**/*.rb")
32
- rd.options << "--all" << "--charset" << "utf-8"
33
- end
34
- end
35
-
36
- begin
37
- require 'jeweler'
38
- Jeweler::Tasks.new do |s|
39
- s.name = "miso"
40
- s.homepage = "http://github.com/Fingertips/miso"
41
- s.email = ["eloy@fngtps.com", "manfred@fngtps.com"]
42
- s.authors = ["Eloy Duran", "Manfred Stienstra"]
43
- s.summary = s.description = "Miso is a unified API for simple image operations commonly used on the web."
44
- s.files -= %w{ .gitignore .kick }
45
- s.add_dependency('executioner', '>= 0.3.0')
46
- end
47
- rescue LoadError
48
- end
49
-
50
- begin
51
- require 'jewelry_portfolio/tasks'
52
- JewelryPortfolio::Tasks.new do |p|
53
- p.account = 'Fingertips'
54
- end
55
- rescue LoadError
56
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.3
@@ -1,75 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{miso}
8
- s.version = "0.3.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Eloy Duran", "Manfred Stienstra"]
12
- s.date = %q{2010-08-17}
13
- s.description = %q{Miso is a unified API for simple image operations commonly used on the web.}
14
- s.email = ["eloy@fngtps.com", "manfred@fngtps.com"]
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README",
18
- "TODO"
19
- ]
20
- s.files = [
21
- "LICENSE",
22
- "README",
23
- "Rakefile",
24
- "TODO",
25
- "VERSION",
26
- "lib/miso.rb",
27
- "lib/miso/factory.rb",
28
- "lib/miso/image.rb",
29
- "lib/miso/processor.rb",
30
- "lib/miso/processor/core_image.rb",
31
- "lib/miso/processor/graphics_magick.rb",
32
- "lib/miso/processor/image_magick.rb",
33
- "miso.gemspec",
34
- "spec/api/factory_spec.rb",
35
- "spec/api/image_spec.rb",
36
- "spec/api/processor_spec.rb",
37
- "spec/api/processors_spec.rb",
38
- "spec/fixtures/120x100.png",
39
- "spec/functional/processor/core_image_spec.rb",
40
- "spec/functional/processor/graphics_magick_spec.rb",
41
- "spec/functional/processor/image_magick_spec.rb",
42
- "spec/functional/processor_spec.rb",
43
- "spec/start.rb"
44
- ]
45
- s.homepage = %q{http://github.com/Fingertips/miso}
46
- s.rdoc_options = ["--charset=UTF-8"]
47
- s.require_paths = ["lib"]
48
- s.rubygems_version = %q{1.3.7}
49
- s.summary = %q{Miso is a unified API for simple image operations commonly used on the web.}
50
- s.test_files = [
51
- "spec/api/factory_spec.rb",
52
- "spec/api/image_spec.rb",
53
- "spec/api/processor_spec.rb",
54
- "spec/api/processors_spec.rb",
55
- "spec/functional/processor/core_image_spec.rb",
56
- "spec/functional/processor/graphics_magick_spec.rb",
57
- "spec/functional/processor/image_magick_spec.rb",
58
- "spec/functional/processor_spec.rb",
59
- "spec/start.rb"
60
- ]
61
-
62
- if s.respond_to? :specification_version then
63
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
- s.specification_version = 3
65
-
66
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<executioner>, [">= 0.3.0"])
68
- else
69
- s.add_dependency(%q<executioner>, [">= 0.3.0"])
70
- end
71
- else
72
- s.add_dependency(%q<executioner>, [">= 0.3.0"])
73
- end
74
- end
75
-
@@ -1,31 +0,0 @@
1
- require File.expand_path('../../start', __FILE__)
2
-
3
- describe "A Miso::Factory instance" do
4
- before do
5
- Miso::Processor.processor_class = Miso::Processor
6
-
7
- Miso::Processor.any_instance.stubs(:write)
8
-
9
- @input_file = fixture_file('120x100.png')
10
- @output_file = '/output_image.png'
11
- @image = Miso::Image.new(@input_file)
12
-
13
- Miso::Image.stubs(:new).with(@input_file, Miso::Processor).returns(@image)
14
- Miso::Image.stubs(:new).with(@output_file, Miso::Processor)
15
-
16
- @factory = Miso::Factory.new
17
- end
18
-
19
- after do
20
- Miso::Processor.processor_class = nil
21
- end
22
-
23
- it "should store operations that are to be applied later on" do
24
- @factory.crop(123, 456).fit(123, 456)
25
-
26
- @image.expects(:crop).with(123, 456)
27
- @image.expects(:fit).with(123, 456)
28
-
29
- @factory.apply(@input_file, @output_file)
30
- end
31
- end
@@ -1,129 +0,0 @@
1
- require File.expand_path('../../start', __FILE__)
2
-
3
- describe "Miso::Image, concerning initialization" do
4
- class FakeProcessor; end
5
-
6
- before do
7
- Miso::Processor.processor_class = nil
8
- end
9
-
10
- after do
11
- Miso::Processor.processor_class = nil
12
- end
13
-
14
- it "should initialize with only a file argument and use the default processor class" do
15
- Miso::Processor.processor_class = Miso::Processor::ImageMagick
16
- image = Miso::Image.new(fixture_file('120x100.png'))
17
-
18
- image.processor.input_file.should == fixture_file('120x100.png')
19
- image.processor.class.should == Miso::Processor::ImageMagick
20
- end
21
-
22
- it "should initialize with a file and processor class" do
23
- image = Miso::Image.new(fixture_file('120x100.png'), Miso::Processor::ImageMagick)
24
-
25
- image.processor.input_file.should == fixture_file('120x100.png')
26
- image.processor.class.should == Miso::Processor::ImageMagick
27
- end
28
- end
29
-
30
- describe "An instance of Miso::Image, concerning forwarding calls to the processor" do
31
- before do
32
- Miso::Processor.any_instance.stubs(:fit)
33
- Miso::Processor.any_instance.stubs(:crop)
34
-
35
- @image = Miso::Image.new(fixture_file('120x100.png'), Miso::Processor)
36
- end
37
-
38
- it "should forward #crop to the processor" do
39
- @image.processor.expects(:crop).with(123, 456)
40
- @image.crop(123, 456)
41
- end
42
-
43
- it "should return self when calling #crop" do
44
- @image.crop(123, 456).should.be @image
45
- end
46
-
47
- it "should forward #fit to the processor" do
48
- @image.processor.expects(:fit).with(123, 456)
49
- @image.fit(123, 456)
50
- end
51
-
52
- it "should return self instance when calling #fit" do
53
- @image.fit(123, 456).should.be @image
54
- end
55
-
56
- it "should forward #dimensions to the processor and return the result" do
57
- @image.processor.expects(:dimensions).returns([123, 456])
58
- @image.dimensions.should == [123, 456]
59
- end
60
-
61
- it "should forward #width and #height to the processor and return the result" do
62
- @image.processor.expects(:width).returns(123)
63
- @image.width.should == 123
64
- end
65
-
66
- it "should forward #height to the processor and return the result" do
67
- @image.processor.expects(:height).returns(456)
68
- @image.height.should == 456
69
- end
70
-
71
- it "should forward #write to the processor and forward its output file to the new instance of Miso::Image" do
72
- @image.processor.expects(:write).with(fixture_file('120x100.png'))
73
- output_image = @image.write(fixture_file('120x100.png'))
74
- output_image.processor.input_file.should == fixture_file('120x100.png')
75
- end
76
- end
77
-
78
- describe "An instance of Miso::Image, concerning combined methods" do
79
- before do
80
- Miso::Processor.any_instance.stubs(:fit)
81
- Miso::Processor.any_instance.stubs(:crop)
82
-
83
- @image = Miso::Image.new(fixture_file('120x100.png'), Miso::Processor)
84
- end
85
-
86
- it "should call #fit to scale and preserve aspect ratio, then call #crop" do
87
- @image.expects(:fit).with(123, 456).returns(@image)
88
- @image.expects(:crop).with(123, 456).returns(@image)
89
-
90
- @image.crop_fitting(123, 456)
91
- end
92
-
93
- it "should return self when calling #crop_fitting" do
94
- @image.crop_fitting(123, 456).should.be @image
95
- end
96
- end
97
-
98
- describe "Miso::Image, concerning shortcut class methods" do
99
- before do
100
- @input_file = fixture_file('120x100.png')
101
- @output_file = temp_file('cropped_to_40x30.png')
102
- @image = Miso::Image.new(@input_file, Miso::Processor)
103
-
104
- Miso::Image.stubs(:new).with(@input_file, nil).returns(@image)
105
- end
106
-
107
- it "should crop to specified dimensions" do
108
- @image.expects(:crop).with(40, 30).returns(@image)
109
- @image.expects(:write).with(@output_file)
110
-
111
- Miso::Image.crop(@input_file, @output_file, 40, 30)
112
- end
113
-
114
- it "should fit to specified dimensions, conserving the original aspect ratio" do
115
- @image.expects(:fit).with(40, 30).returns(@image)
116
- @image.expects(:write).with(@output_file)
117
-
118
- Miso::Image.fit(@input_file, @output_file, 40, 30)
119
- end
120
-
121
- it "should return its dimensions" do
122
- @image.expects(:dimensions).returns([120, 100])
123
- Miso::Image.dimensions(@input_file).should == [120, 100]
124
- end
125
-
126
- it "should make a factory" do
127
- Miso::Image.factory.should.be.a.kind_of(Miso::Factory)
128
- end
129
- end
@@ -1,49 +0,0 @@
1
- require File.expand_path('../../start', __FILE__)
2
-
3
- describe "Miso::Processor" do
4
- before do
5
- Miso::Processor.processor_class = nil
6
- end
7
-
8
- after do
9
- Miso::Processor.processor_class = nil
10
- end
11
-
12
- it "should assign the processor class to use" do
13
- Miso::Processor.processor_class = Miso::Processor::ImageMagick
14
- Miso::Processor.processor_class.should.be Miso::Processor::ImageMagick
15
- end
16
-
17
- it "should find the first available processor class" do
18
- Miso::Processor.processor_classes = [
19
- stub(:available? => false),
20
- stub(:available? => true),
21
- stub(:available? => false)
22
- ]
23
-
24
- Miso::Processor.processor_class.should.be Miso::Processor.processor_classes[1]
25
- end
26
-
27
- it "should raise if no available processor class is found" do
28
- Miso::Processor.processor_classes = [
29
- stub(:available? => false),
30
- stub(:available? => false)
31
- ]
32
-
33
- lambda {
34
- Miso::Processor.processor_class
35
- }.should.raise
36
- end
37
-
38
- it "should initialize with an input file path" do
39
- processor = Miso::Processor.new(fixture_file('120x100.png'))
40
- processor.input_file.should == fixture_file('120x100.png')
41
- end
42
-
43
- it "should returns the width and height" do
44
- processor = Miso::Processor.new(fixture_file('120x100.png'))
45
- processor.stubs(:dimensions).returns([120, 100])
46
- processor.width.should == 120
47
- processor.height.should == 100
48
- end
49
- end
@@ -1,28 +0,0 @@
1
- require File.expand_path('../../start', __FILE__)
2
-
3
- Miso::Processor.processor_classes.each do |processor|
4
- if processor.available?
5
- describe "An instance of #{processor.name}" do
6
- before do
7
- @image_120_x_100 = Miso::Image.new(fixture_file('120x100.png'), processor)
8
- @output_file = temp_file('temp.png')
9
- end
10
-
11
- it "should crop to specified dimensions" do
12
- @image_120_x_100.crop(40, 30).write(@output_file).dimensions.should == [40, 30]
13
- @image_120_x_100.crop(40, 33).write(@output_file).dimensions.should == [40, 33]
14
- end
15
-
16
- it "should fit to specified dimensions, conserving the original aspect ratio" do
17
- @image_120_x_100.fit(40, 30).write(@output_file).dimensions.should == [36, 30]
18
- @image_120_x_100.fit(40, 34).write(@output_file).dimensions.should == [40, 33]
19
- end
20
-
21
- it "should return its dimensions" do
22
- @image_120_x_100.dimensions.should == [120, 100]
23
- end
24
- end
25
- else
26
- warn "[!] Skipping #{processor.name} api spec."
27
- end
28
- end
Binary file
@@ -1,55 +0,0 @@
1
- require File.expand_path('../../../start', __FILE__)
2
-
3
- begin
4
- require 'osx/cocoa'
5
-
6
- describe "Miso::Processor::CoreImage" do
7
- it "should check the load paths to see if RubyCocoa is available" do
8
- Miso::Processor::CoreImage.should.be.available
9
- with_load_path '/tmp', '~/' do
10
- Miso::Processor::CoreImage.should.not.be.available
11
- end
12
- end
13
-
14
- it "should require osx/cocoa on initialization" do
15
- Miso::Processor::CoreImage.any_instance.expects(:require).with('osx/cocoa')
16
- Miso::Processor::CoreImage.new(fixture_file('120x100.png'))
17
- end
18
- end
19
-
20
- describe "An instance of Miso::Processor::CoreImage" do
21
- it "should write the output file with the type inflected from the extension" do
22
- ext_and_type = {
23
- 'png' => 'PNG' ,
24
- 'jpg' => 'JPEG',
25
- 'jpeg' => 'JPEG',
26
- 'gif' => 'GIF' ,
27
- 'tif' => 'TIFF',
28
- 'tiff' => 'TIFF',
29
- 'bmp' => 'bitmap'
30
- }
31
-
32
- ext_and_type.each { |k, v| ext_and_type[k.upcase] = v }
33
-
34
- ext_and_type.each do |ext, type|
35
- Miso::Image.crop(input, output(ext), 100, 100, processor)
36
- file_info(output(ext)).should.include type
37
- end
38
- end
39
-
40
- it "should raise if it can't inflect the type from the extension" do
41
- lambda {
42
- Miso::Image.crop(input, output('foo'), 100, 100, processor)
43
- }.should.raise Miso::UnsupportedFileType
44
- end
45
-
46
- private
47
-
48
- def processor; Miso::Processor::CoreImage end
49
- def input; fixture_file('120x100.png') end
50
- def output(ext); temp_file("temp.#{ext}") end
51
- end
52
-
53
- rescue LoadError
54
- warn "[!] Skipping Miso::Processor::CoreImage functional spec."
55
- end
@@ -1,15 +0,0 @@
1
- require File.expand_path('../../../start', __FILE__)
2
-
3
- if Executioner::ClassMethods.find_executable('gm')
4
- describe "Miso::Processor::GraphicsMagick" do
5
- it "should check the load paths to see if GraphicsMagick is available" do
6
- Miso::Processor::GraphicsMagick.should.be.available
7
-
8
- Miso::Processor::GraphicsMagick.stubs(:find_executable).returns(nil)
9
- Miso::Processor::GraphicsMagick.should.not.be.available
10
- end
11
- end
12
-
13
- else
14
- warn "[!] Skipping Miso::Processor::GraphicsMagick functional spec."
15
- end
@@ -1,15 +0,0 @@
1
- require File.expand_path('../../../start', __FILE__)
2
-
3
- if Executioner::ClassMethods.find_executable('convert')
4
- describe "Miso::Processor::ImageMagick" do
5
- it "should check the load paths to see if ImageMagick is available" do
6
- Miso::Processor::ImageMagick.should.be.available
7
-
8
- Miso::Processor::ImageMagick.stubs(:find_executable).returns(nil)
9
- Miso::Processor::ImageMagick.should.not.be.available
10
- end
11
- end
12
-
13
- else
14
- warn "[!] Skipping Miso::Processor::ImageMagick functional spec."
15
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path('../../start', __FILE__)
2
-
3
- describe "Miso::Processor" do
4
- it "should expand and verify the input file path" do
5
- raised = false
6
- begin
7
- Miso::Processor.new('~/image.png')
8
- rescue Errno::ENOENT => e
9
- raised = true
10
- e.message.should.include File.expand_path('~/image.png')
11
- end
12
- raised.should.be true
13
- end
14
- end
@@ -1,45 +0,0 @@
1
- require 'rubygems' rescue LoadError
2
- require 'test/spec'
3
- require 'mocha'
4
-
5
- require 'fileutils'
6
-
7
- $:.unshift(File.expand_path('../../lib', __FILE__))
8
-
9
- require 'miso'
10
- require 'miso/processor'
11
- require 'miso/processor/core_image'
12
- require 'miso/processor/image_magick'
13
- require 'miso/processor/graphics_magick'
14
-
15
- class Test::Unit::TestCase
16
- TMP_DIR = File.expand_path('../tmp', __FILE__)
17
-
18
- def setup
19
- FileUtils.mkdir_p(TMP_DIR)
20
- end
21
-
22
- def teardown
23
- FileUtils.rm_rf(TMP_DIR)
24
- end
25
-
26
- def fixture_file(name)
27
- File.expand_path("../fixtures/#{name}", __FILE__)
28
- end
29
-
30
- def temp_file(filename)
31
- File.join(TMP_DIR, filename)
32
- end
33
-
34
- def with_load_path(*load_path)
35
- before = $:.dup
36
- $:.replace load_path
37
- yield
38
- ensure
39
- $:.replace before
40
- end
41
-
42
- def file_info(path)
43
- `/usr/bin/env file '#{path}'`.split(':').last.strip
44
- end
45
- end