dimension 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e101e16b7d5ceb6fb18b6d2e82bf856a66383daa
4
+ data.tar.gz: 14510358ffbdbd31f7bce572bf006019d921b763
5
+ SHA512:
6
+ metadata.gz: f72131f1f58b51b054357ad5e11947f7828b9a04dd2f1c9183db84e134197c372bfce11c4fc816d27f4b89a211d4102a8cd47f12b1d27e20bbe87d5f3d641805
7
+ data.tar.gz: 518fb7db8cf2b3befbc595fe754c60b56a7e15916d200d7d76ab221f4b691c0b8624731174f92592d8fe285112b30652868f7520c767fc234b937f1366a2e705
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
+ *~
1
2
  .DS_Store
2
3
  pkg
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- Dimension
2
- =========
1
+ Resizer
2
+ =======
3
3
 
4
4
  Fast, simplified image resizing for Ruby. No ImageMagick.
5
5
 
6
6
  ``` rb
7
- require 'Dimension'
7
+ require 'resizer'
8
8
 
9
- thumb = Dimension.open('tux.png')
9
+ thumb = Resizer.open('tux.png')
10
10
  thumb.generate('100x100') # => { :width => 100, :height => 100 }
11
11
  thumb.save('resized.png')
12
12
  ```
@@ -14,7 +14,7 @@ Fast, simplified image resizing for Ruby. No ImageMagick.
14
14
  Or generate and write file automatically.
15
15
 
16
16
  ``` rb
17
- thumb = Dimension.new('tux.png')
17
+ thumb = Resizer.new('tux.png')
18
18
  thumb.generate!('100x300!') # will write file as 'tux-100x300.png'
19
19
  ```
20
20
 
@@ -23,7 +23,7 @@ Or generate and write file automatically.
23
23
  Yes sir, we have it.
24
24
 
25
25
  ``` rb
26
- thumb = Dimension.open(params[:file])
26
+ thumb = Resizer.open(params[:file])
27
27
  thumb.generate('200x300#')
28
28
  thumb.image_data
29
29
  ```
@@ -32,10 +32,11 @@ You can also pass a block, which will ensure the original image is closed after
32
32
 
33
33
  ``` rb
34
34
  get '/resize/:file' do
35
- thumb = Dimension.open(params[:file])
36
- thumb.generate('200x300#') do
37
- thumb.to_response
35
+ thumb = Resizer.open(params[:file])
36
+ thumb.generate('200x300#') do |res|
37
+ @out = thumb.to_response
38
38
  end
39
+ @out.to_response
39
40
  end
40
41
  ```
41
42
 
@@ -43,11 +44,6 @@ You can also pass a block, which will ensure the original image is closed after
43
44
 
44
45
  This is taken directly from the excellent Dragonfly gem.
45
46
 
46
- Author
47
- ======
48
-
49
- Written by Tomás Pollak.
50
-
51
47
  Copyright
52
48
  =========
53
49
 
data/benchmark.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './lib/dimension'
1
+ require './lib/resizer'
2
2
  require 'benchmark'
3
3
 
4
4
  file = ARGV[0] or abort('File needed')
@@ -10,8 +10,8 @@ puts "Processing #{file}"
10
10
  Benchmark.bm do |x|
11
11
 
12
12
  x.report do
13
- Dimension.processor = 'imlib2'
14
- a = Dimension.open(file)
13
+ Resizer.processor = 'imlib2'
14
+ a = Resizer.open(file)
15
15
  res = a.generate!(geometry)
16
16
  puts res.inspect
17
17
  end
@@ -19,8 +19,8 @@ Benchmark.bm do |x|
19
19
  sleep 1
20
20
 
21
21
  x.report do
22
- Dimension.processor = 'image_magick'
23
- b = Dimension.open(file)
22
+ Resizer.processor = 'image_magick'
23
+ b = Resizer.open(file)
24
24
  res = b.generate!(geometry)
25
25
  puts res.inspect
26
26
  end
data/bin/dimension CHANGED
@@ -3,9 +3,15 @@
3
3
  require './lib/dimension'
4
4
  require 'benchmark'
5
5
 
6
- file = ARGV[0] or abort('File needed. Try with examples/assets/chair.jpg')
7
- geometry = ARGV[1] or abort('Geometry required. Example: 100x100')
6
+ def usage
7
+ puts 'Usage: dimension [file] [geometry] [output file/path]'
8
+ puts 'Example: dimension example/assets/chair.jpg 100x100 /tmp'
9
+ abort
10
+ end
11
+
12
+ file = ARGV[0] # or abort('File needed. Try with examples/assets/chair.jpg')
13
+ geometry = ARGV[1] or usage
14
+ output = ARGV[2]
8
15
 
9
16
  thumb = Dimension.open(file)
10
- res = thumb.generate!(geometry)
11
- # puts res.inspect
17
+ res = thumb.generate!(geometry, output)
data/examples/sinatra.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  ROOT = File.expand_path(File.dirname(__FILE__))
2
2
 
3
3
  require 'sinatra'
4
- require ROOT + '/../lib/dimension'
4
+ require ROOT + '/../lib/resizer'
5
5
 
6
6
  get '/' do
7
7
  images = Dir.glob(File.join(ROOT, 'assets') + '/*')
@@ -21,7 +21,7 @@ get '/images/:file' do
21
21
  end
22
22
 
23
23
  begin
24
- thumb = Dimension.open(file)
24
+ thumb = Resizer.open(file)
25
25
  rescue => e
26
26
  return e.message
27
27
  end
@@ -29,6 +29,9 @@ class Image
29
29
  end
30
30
 
31
31
  @file = File.expand_path(file)
32
+ @name = File.basename(file)
33
+ @path = File.dirname(@file)
34
+
32
35
  raise ArgumentError, "File not found: #{@file}" unless File.exist?(@file)
33
36
  log "File loaded: #{file}. Geometry: #{geometry.join('x')}"
34
37
  end
@@ -61,7 +64,7 @@ class Image
61
64
  else
62
65
  raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
63
66
  end
64
-
67
+
65
68
  new_geometry = get_new_geometry
66
69
  {:width => new_geometry[0], :height => new_geometry[1]}
67
70
  end
@@ -69,8 +72,15 @@ class Image
69
72
  def save(out_file)
70
73
  new_geometry = get_new_geometry
71
74
 
75
+ path = @path
76
+
77
+ if out_file and File.directory?(out_file)
78
+ path = File.expand_path(out_file)
79
+ out_file = nil
80
+ end
81
+
72
82
  if out_file.nil?
73
- out_file = file.sub(File.extname(file), '-' + new_geometry.join('x') + File.extname(file))
83
+ out_file = File.join(path, @name.sub(File.extname(file), '-' + new_geometry.join('x') + File.extname(file)))
74
84
  end
75
85
 
76
86
  log "Writing file: #{out_file}"
@@ -83,11 +93,11 @@ class Image
83
93
  def to_s
84
94
  image_data
85
95
  end
86
-
96
+
87
97
  def to_a
88
98
  to_response
89
99
  end
90
-
100
+
91
101
  def inspect
92
102
  geometry = get_new_geometry
93
103
  "#<Dimension::Image:#{object_id} @width=#{geometry[0]}, @height=#{geometry[1]}>"
@@ -1,7 +1,7 @@
1
1
  module Dimension
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- PATCH = 2
4
+ PATCH = 3
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
data/lib/dimension.rb CHANGED
@@ -1,5 +1,5 @@
1
- # require File.expand_path(File.dirname(__FILE__)) + '/image'
2
- require 'dimension/image'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/dimension/image'
2
+ # require 'dimension/image'
3
3
 
4
4
  module Dimension
5
5
 
@@ -20,11 +20,11 @@ module Dimension
20
20
  require_relative "dimension/processors/#{name}"
21
21
  Image.include(Kernel.const_get(@processor))
22
22
  end
23
-
23
+
24
24
  def self.open(file)
25
25
  Image.new(file)
26
26
  end
27
-
27
+
28
28
  end
29
29
 
30
30
  begin
metadata CHANGED
@@ -1,34 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dimension
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
10
5
  platform: ruby
11
- authors:
12
- - "Tom\xC3\xA1s Pollak"
6
+ authors:
7
+ - Tomás Pollak
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2014-04-04 00:00:00 -07:00
18
- default_executable:
11
+ date: 2014-04-09 00:00:00.000000000 Z
19
12
  dependencies: []
20
-
21
13
  description: Yes, there are other graphic libraries besides ImageMagick.
22
- email:
14
+ email:
23
15
  - tomas@forkhq.com
24
- executables:
16
+ executables:
25
17
  - dimension
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
31
- - .gitignore
20
+ files:
21
+ - ".gitignore"
32
22
  - README.md
33
23
  - Rakefile
34
24
  - benchmark.rb
@@ -44,37 +34,28 @@ files:
44
34
  - lib/dimension/processors/image_magick.rb
45
35
  - lib/dimension/processors/imlib2.rb
46
36
  - lib/dimension/version.rb
47
- has_rdoc: true
48
37
  homepage: https://github.com/tomas/dimension
49
38
  licenses: []
50
-
39
+ metadata: {}
51
40
  post_install_message:
52
41
  rdoc_options: []
53
-
54
- require_paths:
42
+ require_paths:
55
43
  - lib
56
- required_ruby_version: !ruby/object:Gem::Requirement
57
- requirements:
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
58
46
  - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
64
- requirements:
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
65
51
  - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 1
69
- - 3
70
- - 6
52
+ - !ruby/object:Gem::Version
71
53
  version: 1.3.6
72
54
  requirements: []
73
-
74
55
  rubyforge_project: dimension
75
- rubygems_version: 1.3.6
56
+ rubygems_version: 2.2.0
76
57
  signing_key:
77
- specification_version: 3
58
+ specification_version: 4
78
59
  summary: Native, in-process image resizing in Ruby.
79
60
  test_files: []
80
-
61
+ has_rdoc: