dimension 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e101e16b7d5ceb6fb18b6d2e82bf856a66383daa
4
- data.tar.gz: 14510358ffbdbd31f7bce572bf006019d921b763
3
+ metadata.gz: 6cf302e4bb1fc448c02a78c5c8301b16f3f3b3e8
4
+ data.tar.gz: c6f093638b2ac08b6cf18f23b37ca6c8bdceaf3b
5
5
  SHA512:
6
- metadata.gz: f72131f1f58b51b054357ad5e11947f7828b9a04dd2f1c9183db84e134197c372bfce11c4fc816d27f4b89a211d4102a8cd47f12b1d27e20bbe87d5f3d641805
7
- data.tar.gz: 518fb7db8cf2b3befbc595fe754c60b56a7e15916d200d7d76ab221f4b691c0b8624731174f92592d8fe285112b30652868f7520c767fc234b937f1366a2e705
6
+ metadata.gz: 88bae316d7293757aa1699835e5d685c564315ca513ccafa9ffabb1384605b0f34807f06cfca5758ba7363eba75bc4c425205ecde4be738bcca6766652e5f25a
7
+ data.tar.gz: e511c93b2e6e4cc5dce4e8858498508eb6d8f82be4acd278f92996e0dad154e009d6520c5cbc42466c65b5323b3c75dbdc1805d253386f77f5c21eefcb25ed45
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- Resizer
2
- =======
1
+ Dimension
2
+ =========
3
3
 
4
4
  Fast, simplified image resizing for Ruby. No ImageMagick.
5
5
 
6
6
  ``` rb
7
- require 'resizer'
7
+ require 'Dimension'
8
8
 
9
- thumb = Resizer.open('tux.png')
9
+ thumb = Dimension.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 = Resizer.new('tux.png')
17
+ thumb = Dimension.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 = Resizer.open(params[:file])
26
+ thumb = Dimension.open(params[:file])
27
27
  thumb.generate('200x300#')
28
28
  thumb.image_data
29
29
  ```
@@ -32,11 +32,10 @@ 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 = Resizer.open(params[:file])
36
- thumb.generate('200x300#') do |res|
37
- @out = thumb.to_response
35
+ thumb = Dimension.open(params[:file])
36
+ thumb.generate('200x300#') do
37
+ thumb.to_response
38
38
  end
39
- @out.to_response
40
39
  end
41
40
  ```
42
41
 
@@ -44,6 +43,11 @@ You can also pass a block, which will ensure the original image is closed after
44
43
 
45
44
  This is taken directly from the excellent Dragonfly gem.
46
45
 
46
+ Author
47
+ ======
48
+
49
+ Written by Tomás Pollak.
50
+
47
51
  Copyright
48
52
  =========
49
53
 
data/benchmark.rb CHANGED
@@ -1,4 +1,4 @@
1
- require './lib/resizer'
1
+ require './lib/dimension'
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
- Resizer.processor = 'imlib2'
14
- a = Resizer.open(file)
13
+ Dimension.processor = 'imlib2'
14
+ a = Dimension.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
- Resizer.processor = 'image_magick'
23
- b = Resizer.open(file)
22
+ Dimension.processor = 'image_magick'
23
+ b = Dimension.open(file)
24
24
  res = b.generate!(geometry)
25
25
  puts res.inspect
26
26
  end
@@ -0,0 +1,26 @@
1
+ ROOT = File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'thin'
4
+ require 'rack/builder'
5
+ require 'rack/static'
6
+
7
+ require ROOT + '/../lib/dimension'
8
+ require ROOT + '/../lib/dimension/middleware'
9
+
10
+ app = Rack::Builder.new do
11
+
12
+ root = File.join(ROOT, 'assets')
13
+
14
+ use Dimension::Middleware, { :root => root }
15
+
16
+ use Rack::Static,
17
+ :urls => ['/'],
18
+ :root => root
19
+
20
+ run lambda { |env|
21
+ [ 200, { 'Content-Type' => 'text/html'}, ['Not Found.'] ]
22
+ }
23
+
24
+ end.to_app
25
+
26
+ Thin::Server.start('0.0.0.0', 4567, app)
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/resizer'
4
+ require ROOT + '/../lib/dimension'
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 = Resizer.open(file)
24
+ thumb = Dimension.open(file)
25
25
  rescue => e
26
26
  return e.message
27
27
  end
@@ -18,7 +18,7 @@ class Image
18
18
 
19
19
  # Geometry string patterns
20
20
  RESIZE_GEOMETRY = /^(\d+)?x(\d+)?[><%^!]?$|^\d+@$/ # e.g. '300x200!'
21
- CROPPED_RESIZE_GEOMETRY = /^(\d+)x(\d+)#(\w{1,2})?$/ # e.g. '20x50#ne'
21
+ CROPPED_RESIZE_GEOMETRY = /^(\d+)x(\d+)[:|#](\w{1,2})?$/ # e.g. '20x50:ne'
22
22
  CROP_GEOMETRY = /^(\d+)x(\d+)([+-]\d+)?([+-]\d+)?(\w{1,2})?$/ # e.g. '30x30+10+10'
23
23
 
24
24
  attr_reader :file
@@ -52,7 +52,7 @@ class Image
52
52
 
53
53
  def resize_to(geometry)
54
54
  case geometry
55
- when RESIZE_GEOMETRY
55
+ when RESIZE_GEOMETRY
56
56
  log "Resize -- #{$1}x#{$2}"
57
57
  resize($1, $2)
58
58
  when CROPPED_RESIZE_GEOMETRY
@@ -0,0 +1,35 @@
1
+ module Dimension
2
+
3
+ class Middleware
4
+
5
+ FORMATS = ['.jpg', '.png', '.gif', '.jpeg']
6
+
7
+ def initialize(app, opts = {})
8
+ @app = app
9
+ @root = File.expand_path(opts[:root] || Dir.pwd())
10
+ end
11
+
12
+ def call(env)
13
+ url = env['PATH_INFO']
14
+ query = env['QUERY_STRING']
15
+ geometry = query && query[/geometry=([^\&|$]+)/, 1]
16
+
17
+ if geometry and ext = File.extname(url) and ext != '' and FORMATS.include?(ext.downcase)
18
+ file = File.join(@root, url)
19
+ # puts 'Processing image: ' + file
20
+
21
+ image = Dimension.open(file)
22
+ image.generate(geometry) do
23
+ image.to_response
24
+ end
25
+ end
26
+
27
+ @app.call(env)
28
+ rescue ArgumentError => e # Dimension::Error
29
+ # puts "Error processing image: #{e.message}"
30
+ @app.call(env)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -86,7 +86,7 @@ module Imlib2Processor
86
86
  end
87
87
 
88
88
  def crop(width, height, x, y, gravity)
89
- rect = [x || 0, y || 0, width.to_i, height.to_i]
89
+ rect = [(x || 0).to_i, (y || 0).to_i, width.to_i, height.to_i]
90
90
  image.crop!(rect)
91
91
  end
92
92
 
@@ -119,7 +119,7 @@ module Imlib2Processor
119
119
  end
120
120
 
121
121
  def get_resize_geometry(w, h, to_longer = true)
122
- if to_longer
122
+ if to_longer or h.nil?
123
123
  if image.w < image.h
124
124
  new_h = ((w.to_f / image.w) * image.h).round
125
125
  return w.to_i, new_h
@@ -1,7 +1,7 @@
1
1
  module Dimension
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- PATCH = 3
4
+ PATCH = 4
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Yes, there are other graphic libraries besides ImageMagick.
14
14
  email:
@@ -28,9 +28,11 @@ files:
28
28
  - examples/assets/chair.jpg
29
29
  - examples/assets/the-two-towers.png
30
30
  - examples/assets/window.jpg
31
+ - examples/middleware.rb
31
32
  - examples/sinatra.rb
32
33
  - lib/dimension.rb
33
34
  - lib/dimension/image.rb
35
+ - lib/dimension/middleware.rb
34
36
  - lib/dimension/processors/image_magick.rb
35
37
  - lib/dimension/processors/imlib2.rb
36
38
  - lib/dimension/version.rb
@@ -58,4 +60,3 @@ signing_key:
58
60
  specification_version: 4
59
61
  summary: Native, in-process image resizing in Ruby.
60
62
  test_files: []
61
- has_rdoc: