imagery 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/imagery.rb +20 -0
- data/lib/imagery/faking.rb +30 -0
- data/lib/imagery/model.rb +85 -0
- data/lib/imagery/s3.rb +74 -0
- data/test/fixtures/lake.jpg +0 -0
- data/test/helper.rb +12 -0
- data/test/test_imagery.rb +152 -0
- data/test/test_with_s3.rb +116 -0
- metadata +125 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Cyril David
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= imagery
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Cyril David. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "imagery"
|
8
|
+
gem.summary = %Q{Image resizing without all the bloat}
|
9
|
+
gem.description = %Q{Uses ImageMagick directly underneath. Nuff said.}
|
10
|
+
gem.email = "cyx.ucron@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/sinefunc/imagery"
|
12
|
+
gem.authors = ["Cyril David"]
|
13
|
+
gem.add_dependency "escape", ">= 0"
|
14
|
+
gem.add_development_dependency "contest", ">= 0"
|
15
|
+
gem.add_development_dependency "aws-s3", ">= 0"
|
16
|
+
gem.add_development_dependency "mocha", ">= 0"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/test_*.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "imagery #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/imagery.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'escape'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Imagery
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
|
7
|
+
autoload :Model, "imagery/model"
|
8
|
+
autoload :Faking, "imagery/faking"
|
9
|
+
autoload :S3, "imagery/s3"
|
10
|
+
|
11
|
+
def new(*args, &blk)
|
12
|
+
Model.new(*args, &blk)
|
13
|
+
end
|
14
|
+
module_function :new
|
15
|
+
|
16
|
+
def faked(&blk)
|
17
|
+
Model.faked(&blk)
|
18
|
+
end
|
19
|
+
module_function :faked
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Imagery
|
2
|
+
module Faking
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def mode=(mode)
|
9
|
+
@mode = mode
|
10
|
+
end
|
11
|
+
|
12
|
+
def mode
|
13
|
+
@mode
|
14
|
+
end
|
15
|
+
|
16
|
+
def faked
|
17
|
+
@omode, @mode = @mode, :fake
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
@mode = @omode
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save(io)
|
25
|
+
return true if self.class.mode == :fake
|
26
|
+
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Imagery
|
2
|
+
class Model
|
3
|
+
UnknownSize = Class.new(StandardError)
|
4
|
+
|
5
|
+
attr :key
|
6
|
+
attr :namespace
|
7
|
+
attr :default
|
8
|
+
attr :directory
|
9
|
+
|
10
|
+
attr_writer :root, :sizes
|
11
|
+
|
12
|
+
def initialize(model, key = model.id, namespace = model.class.name.split('::').last.downcase)
|
13
|
+
@key = key.to_s
|
14
|
+
@namespace = namespace
|
15
|
+
@default = { :original => ["1920x1200>"] }
|
16
|
+
@directory = 'public/system'
|
17
|
+
@sizes = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def sizes
|
21
|
+
@sizes.merge(@default)
|
22
|
+
end
|
23
|
+
|
24
|
+
def file(size = :original)
|
25
|
+
raise UnknownSize, "#{ size } is not defined" unless sizes.has_key?(size)
|
26
|
+
|
27
|
+
root_path(directory, namespace, key, filename(size))
|
28
|
+
end
|
29
|
+
|
30
|
+
def tmp
|
31
|
+
root_path(directory, namespace, key, 'tmp')
|
32
|
+
end
|
33
|
+
|
34
|
+
def url(size = :original)
|
35
|
+
file(size).split('public').last
|
36
|
+
end
|
37
|
+
|
38
|
+
module Persistence
|
39
|
+
def save(io)
|
40
|
+
FileUtils.mkdir_p(File.dirname(tmp))
|
41
|
+
File.open(tmp, "wb") { |target| target.write(io.read) }
|
42
|
+
sizes.keys.each { |size| convert(size) }
|
43
|
+
FileUtils.rm(tmp)
|
44
|
+
|
45
|
+
return true
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete
|
49
|
+
FileUtils.rm_rf File.dirname(file)
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
include Persistence
|
54
|
+
|
55
|
+
private
|
56
|
+
def filename(size)
|
57
|
+
"%s.png" % size
|
58
|
+
end
|
59
|
+
|
60
|
+
def convert(size, geometry = self.sizes[size][0], extent = self.sizes[size][1])
|
61
|
+
`#{ cmd size }`
|
62
|
+
end
|
63
|
+
|
64
|
+
def cmd(size, geometry = self.sizes[size][0], extent = self.sizes[size][1])
|
65
|
+
cmd = [].tap do |cmd|
|
66
|
+
cmd.push 'convert', tmp
|
67
|
+
cmd.push '-thumbnail', geometry
|
68
|
+
cmd.push '-gravity', 'center'
|
69
|
+
cmd.push '-extent', extent if extent
|
70
|
+
cmd.push file(size)
|
71
|
+
end
|
72
|
+
|
73
|
+
Escape.shell_command(cmd)
|
74
|
+
end
|
75
|
+
|
76
|
+
def root(root = defined?(ROOT_DIR) && ROOT_DIR)
|
77
|
+
@root ||= root if root
|
78
|
+
@root
|
79
|
+
end
|
80
|
+
|
81
|
+
def root_path(*args)
|
82
|
+
File.join(root, *args)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/imagery/s3.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'aws/s3'
|
2
|
+
|
3
|
+
module Imagery
|
4
|
+
module S3
|
5
|
+
def self.included(base)
|
6
|
+
class << base
|
7
|
+
attr_accessor :s3_bucket, :s3_distribution_domain
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
S3_HOST = "http://s3.amazonaws.com"
|
12
|
+
|
13
|
+
def url(size = :original)
|
14
|
+
if domain = self.class.s3_distribution_domain
|
15
|
+
[domain, namespace, key, filename(size)].join('/')
|
16
|
+
else
|
17
|
+
[S3_HOST, self.class.s3_bucket, namespace, key, filename(size)].join('/')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def save(io)
|
22
|
+
if super
|
23
|
+
s3_object_keys.each do |key, size|
|
24
|
+
Gateway.store(key,
|
25
|
+
File.open(file(size)),
|
26
|
+
self.class.s3_bucket,
|
27
|
+
:access => :public_read,
|
28
|
+
:content_type => "image/png"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete
|
35
|
+
super
|
36
|
+
s3_object_keys.each do |key, size|
|
37
|
+
Gateway.delete key, self.class.s3_bucket
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
def s3_object_keys
|
43
|
+
sizes.keys.map do |size|
|
44
|
+
[[namespace, key, filename(size)].join('/'), size]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module Gateway
|
49
|
+
def store(*args)
|
50
|
+
execute(:store, *args)
|
51
|
+
end
|
52
|
+
module_function :store
|
53
|
+
|
54
|
+
def delete(*args)
|
55
|
+
execute(:delete, *args)
|
56
|
+
end
|
57
|
+
module_function :delete
|
58
|
+
|
59
|
+
private
|
60
|
+
def execute(command, *args)
|
61
|
+
begin
|
62
|
+
AWS::S3::S3Object.__send__(command, *args)
|
63
|
+
rescue AWS::S3::NoConnectionEstablished
|
64
|
+
AWS::S3::Base.establish_connection!(
|
65
|
+
:access_key_id => ENV["AMAZON_ACCESS_KEY_ID"],
|
66
|
+
:secret_access_key => ENV["AMAZON_SECRET_ACCESS_KEY"]
|
67
|
+
)
|
68
|
+
retry
|
69
|
+
end
|
70
|
+
end
|
71
|
+
module_function :execute
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'contest'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'imagery'
|
9
|
+
|
10
|
+
class Test::Unit::TestCase
|
11
|
+
FIXTURES = File.dirname(__FILE__) + '/fixtures'
|
12
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
class Imagery::Model
|
5
|
+
include Imagery::Faking
|
6
|
+
end
|
7
|
+
|
8
|
+
class TestImagery < Test::Unit::TestCase
|
9
|
+
Photo = Class.new(Struct.new(:id))
|
10
|
+
|
11
|
+
test "namespace" do
|
12
|
+
assert_equal 'photo', Imagery.new(Photo.new(1001)).namespace
|
13
|
+
end
|
14
|
+
|
15
|
+
test "key" do
|
16
|
+
assert_equal '1001', Imagery.new(Photo.new(1001)).key
|
17
|
+
end
|
18
|
+
|
19
|
+
test "root_path when no ROOT_DIR" do
|
20
|
+
imagery = Imagery.new(Photo.new(1001))
|
21
|
+
imagery.root = '/'
|
22
|
+
assert_equal "/public/system/photo/1001/tmp", imagery.tmp
|
23
|
+
end
|
24
|
+
|
25
|
+
test "root_path when ROOT_DIR defined on imagery" do
|
26
|
+
Imagery::ROOT_DIR = '/root/dir'
|
27
|
+
|
28
|
+
imagery = Imagery.new(Photo.new(1001))
|
29
|
+
assert_equal "/root/dir/public/system/photo/1001/tmp", imagery.tmp
|
30
|
+
|
31
|
+
Imagery.send :remove_const, :ROOT_DIR
|
32
|
+
end
|
33
|
+
|
34
|
+
test "root_path when ROOT_DIR defined on object" do
|
35
|
+
Object::ROOT_DIR = '/root/dir'
|
36
|
+
|
37
|
+
imagery = Imagery.new(Photo.new(1001))
|
38
|
+
assert_equal "/root/dir/public/system/photo/1001/tmp", imagery.tmp
|
39
|
+
|
40
|
+
Object.send :remove_const, :ROOT_DIR
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "file" do
|
44
|
+
setup do
|
45
|
+
@imagery = Imagery.new(Photo.new(1001))
|
46
|
+
@imagery.root = '/r/d'
|
47
|
+
@imagery.sizes = { :thumb => ['10x10'] }
|
48
|
+
end
|
49
|
+
|
50
|
+
test "file by default" do
|
51
|
+
assert_equal "/r/d/public/system/photo/1001/original.png", @imagery.file
|
52
|
+
end
|
53
|
+
|
54
|
+
test "file given a size" do
|
55
|
+
assert_equal "/r/d/public/system/photo/1001/thumb.png", @imagery.file(:thumb)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "convert" do
|
60
|
+
setup do
|
61
|
+
@imagery = Imagery.new(Photo.new(1001))
|
62
|
+
@imagery.root = '/r/d'
|
63
|
+
@imagery.sizes = {
|
64
|
+
:thumb => ["56x56^"],
|
65
|
+
:small => ["56x56^", "56x56"]
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
test "default resize" do
|
70
|
+
expected =
|
71
|
+
"convert /r/d/public/system/photo/1001/tmp -thumbnail '56x56^' " +
|
72
|
+
"-gravity center /r/d/public/system/photo/1001/thumb.png"
|
73
|
+
|
74
|
+
assert_equal expected, @imagery.send(:cmd, :thumb),
|
75
|
+
end
|
76
|
+
|
77
|
+
test "resize with extent param" do
|
78
|
+
expected =
|
79
|
+
"convert /r/d/public/system/photo/1001/tmp -thumbnail '56x56^' " +
|
80
|
+
"-gravity center -extent 56x56 /r/d/public/system/photo/1001/small.png"
|
81
|
+
|
82
|
+
assert_equal expected, @imagery.send(:cmd, :small)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "saving" do
|
87
|
+
setup do
|
88
|
+
@imagery = Imagery.new(Photo.new(1001))
|
89
|
+
@imagery.root = '/tmp'
|
90
|
+
@imagery.sizes = {
|
91
|
+
:thumb => ["56x56^"],
|
92
|
+
:small => ["100x100^", "100x100"],
|
93
|
+
:large => ["200x200>", "200x200"]
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
teardown do
|
98
|
+
FileUtils.rm_rf '/tmp/public'
|
99
|
+
end
|
100
|
+
|
101
|
+
test "writes all the different geometry sizes normally" do
|
102
|
+
assert @imagery.save(File.open(FIXTURES + '/lake.jpg'))
|
103
|
+
|
104
|
+
assert File.exist?(@imagery.file)
|
105
|
+
assert File.exist?(@imagery.file(:thumb))
|
106
|
+
assert File.exist?(@imagery.file(:small))
|
107
|
+
assert File.exist?(@imagery.file(:large))
|
108
|
+
end
|
109
|
+
|
110
|
+
test "able to delete them" do
|
111
|
+
@imagery.save(File.open(FIXTURES + '/lake.jpg'))
|
112
|
+
@imagery.delete
|
113
|
+
|
114
|
+
assert ! File.exist?(@imagery.file)
|
115
|
+
assert ! File.exist?(@imagery.file(:thumb))
|
116
|
+
assert ! File.exist?(@imagery.file(:small))
|
117
|
+
assert ! File.exist?(@imagery.file(:large))
|
118
|
+
end
|
119
|
+
|
120
|
+
test "when mode == :fake" do
|
121
|
+
time = Benchmark.realtime {
|
122
|
+
Imagery.faked {
|
123
|
+
assert @imagery.save(File.open(FIXTURES + '/lake.jpg'))
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
assert time < 0.01, "Faked context should run in less than 0.01 secs"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "url" do
|
132
|
+
setup do
|
133
|
+
@imagery = Imagery.new(Photo.new(1001))
|
134
|
+
@imagery.root = '/tmp'
|
135
|
+
@imagery.sizes = { :small => ["40x40"] }
|
136
|
+
end
|
137
|
+
|
138
|
+
test "original" do
|
139
|
+
assert_equal '/system/photo/1001/original.png', @imagery.url
|
140
|
+
end
|
141
|
+
|
142
|
+
test "small" do
|
143
|
+
assert_equal '/system/photo/1001/small.png', @imagery.url(:small)
|
144
|
+
end
|
145
|
+
|
146
|
+
test "non-existent" do
|
147
|
+
assert_raise Imagery::Model::UnknownSize do
|
148
|
+
@imagery.url(:foo)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class WithS3Test < Test::Unit::TestCase
|
4
|
+
class WithS3 < Imagery::Model
|
5
|
+
include Imagery::Faking
|
6
|
+
include Imagery::S3
|
7
|
+
|
8
|
+
self.s3_bucket = "tmp-bucket-name"
|
9
|
+
end
|
10
|
+
|
11
|
+
SuperSecretPhoto = Class.new(Struct.new(:id))
|
12
|
+
|
13
|
+
test "urls" do
|
14
|
+
imagery = WithS3.new(SuperSecretPhoto.new(1001))
|
15
|
+
imagery.root = '/tmp'
|
16
|
+
imagery.sizes = {
|
17
|
+
:thumb => ["56x56^"],
|
18
|
+
:small => ["100x100^", "100x100"],
|
19
|
+
:large => ["200x200>", "200x200"]
|
20
|
+
}
|
21
|
+
|
22
|
+
s = 'http://s3.amazonaws.com/tmp-bucket-name/supersecretphoto/1001/%s.png'
|
23
|
+
|
24
|
+
assert_equal s % 'original', imagery.url
|
25
|
+
assert_equal s % 'original', imagery.url(:original)
|
26
|
+
assert_equal s % 'thumb', imagery.url(:thumb)
|
27
|
+
assert_equal s % 'small', imagery.url(:small)
|
28
|
+
assert_equal s % 'large', imagery.url(:large)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "urls with a distribution domain" do
|
32
|
+
imagery = WithS3.new(SuperSecretPhoto.new(1001))
|
33
|
+
imagery.root = '/tmp'
|
34
|
+
imagery.sizes = {
|
35
|
+
:thumb => ["56x56^"],
|
36
|
+
:small => ["100x100^", "100x100"],
|
37
|
+
:large => ["200x200>", "200x200"]
|
38
|
+
}
|
39
|
+
|
40
|
+
s = 'http://assets.site.com/supersecretphoto/1001/%s.png'
|
41
|
+
|
42
|
+
WithS3.s3_distribution_domain = 'http://assets.site.com'
|
43
|
+
|
44
|
+
assert_equal s % 'original', imagery.url
|
45
|
+
assert_equal s % 'original', imagery.url(:original)
|
46
|
+
assert_equal s % 'thumb', imagery.url(:thumb)
|
47
|
+
assert_equal s % 'small', imagery.url(:small)
|
48
|
+
assert_equal s % 'large', imagery.url(:large)
|
49
|
+
|
50
|
+
WithS3.s3_distribution_domain = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
test "saving and storing" do
|
54
|
+
imagery = WithS3.new(SuperSecretPhoto.new(1001))
|
55
|
+
imagery.root = '/tmp'
|
56
|
+
imagery.sizes = {
|
57
|
+
:thumb => ["56x56^"],
|
58
|
+
:small => ["100x100^", "100x100"],
|
59
|
+
:large => ["200x200>", "200x200"]
|
60
|
+
}
|
61
|
+
|
62
|
+
File.stubs(:open).returns(:contents)
|
63
|
+
|
64
|
+
Imagery::S3::Gateway.expects(:store).with() { |key, io, bucket, hash|
|
65
|
+
key == "supersecretphoto/1001/thumb.png" && bucket == 'tmp-bucket-name' &&
|
66
|
+
hash[:access] == :public_read && hash[:content_type] == 'image/png' &&
|
67
|
+
io == :contents
|
68
|
+
}
|
69
|
+
|
70
|
+
Imagery::S3::Gateway.expects(:store).with() { |key, io, bucket, hash|
|
71
|
+
key == "supersecretphoto/1001/small.png" && bucket == 'tmp-bucket-name' &&
|
72
|
+
hash[:access] == :public_read && hash[:content_type] == 'image/png' &&
|
73
|
+
io == :contents
|
74
|
+
}
|
75
|
+
|
76
|
+
Imagery::S3::Gateway.expects(:store).with() { |key, io, bucket, hash|
|
77
|
+
key == "supersecretphoto/1001/large.png" && bucket == 'tmp-bucket-name' &&
|
78
|
+
hash[:access] == :public_read && hash[:content_type] == 'image/png' &&
|
79
|
+
io == :contents
|
80
|
+
}
|
81
|
+
|
82
|
+
Imagery::S3::Gateway.expects(:store).with() { |key, io, bucket, hash|
|
83
|
+
key == "supersecretphoto/1001/original.png" && bucket == 'tmp-bucket-name' &&
|
84
|
+
hash[:access] == :public_read && hash[:content_type] == 'image/png' &&
|
85
|
+
io == :contents
|
86
|
+
}
|
87
|
+
|
88
|
+
WithS3.faked do
|
89
|
+
assert imagery.save(File.open(FIXTURES + '/lake.jpg'))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
test "deleting" do
|
94
|
+
imagery = WithS3.new(SuperSecretPhoto.new(1001))
|
95
|
+
imagery.root = '/tmp'
|
96
|
+
imagery.sizes = {
|
97
|
+
:thumb => ["56x56^"],
|
98
|
+
:small => ["100x100^", "100x100"],
|
99
|
+
:large => ["200x200>", "200x200"]
|
100
|
+
}
|
101
|
+
|
102
|
+
Imagery::S3::Gateway.expects(:delete).
|
103
|
+
with('supersecretphoto/1001/thumb.png', 'tmp-bucket-name')
|
104
|
+
|
105
|
+
Imagery::S3::Gateway.expects(:delete).
|
106
|
+
with('supersecretphoto/1001/small.png', 'tmp-bucket-name')
|
107
|
+
|
108
|
+
Imagery::S3::Gateway.expects(:delete).
|
109
|
+
with('supersecretphoto/1001/large.png', 'tmp-bucket-name')
|
110
|
+
|
111
|
+
Imagery::S3::Gateway.expects(:delete).
|
112
|
+
with('supersecretphoto/1001/original.png', 'tmp-bucket-name')
|
113
|
+
|
114
|
+
assert imagery.delete
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imagery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Cyril David
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-28 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: escape
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: contest
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: aws-s3
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id004
|
68
|
+
description: Uses ImageMagick directly underneath. Nuff said.
|
69
|
+
email: cyx.ucron@gmail.com
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .gitignore
|
80
|
+
- LICENSE
|
81
|
+
- README.rdoc
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- lib/imagery.rb
|
85
|
+
- lib/imagery/faking.rb
|
86
|
+
- lib/imagery/model.rb
|
87
|
+
- lib/imagery/s3.rb
|
88
|
+
- test/fixtures/lake.jpg
|
89
|
+
- test/helper.rb
|
90
|
+
- test/test_imagery.rb
|
91
|
+
- test/test_with_s3.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/sinefunc/imagery
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- --charset=UTF-8
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.3.6
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Image resizing without all the bloat
|
122
|
+
test_files:
|
123
|
+
- test/helper.rb
|
124
|
+
- test/test_imagery.rb
|
125
|
+
- test/test_with_s3.rb
|