imagecache 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +18 -0
- data/.gitignore +4 -1
- data/.rspec +2 -0
- data/.rubocop.yml +1156 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +54 -5
- data/README.md +22 -2
- data/Rakefile +2 -6
- data/circle.yml +11 -0
- data/imagecache.gemspec +0 -1
- data/lib/imagecache.rb +4 -4
- data/lib/imagecache/{backends → backend}/filesystem.rb +8 -4
- data/lib/imagecache/{backends → backend}/redis.rb +1 -1
- data/lib/imagecache/{backends → backend}/s3.rb +1 -1
- data/lib/imagecache/base.rb +17 -4
- data/lib/imagecache/conversions/crop.rb +5 -1
- data/lib/imagecache/conversions/fit.rb +6 -1
- data/lib/imagecache/conversions/resize.rb +7 -4
- data/lib/imagecache/conversions/round.rb +6 -5
- data/lib/imagecache/converter.rb +4 -3
- data/lib/imagecache/identify.rb +3 -1
- data/lib/imagecache/url_reader.rb +3 -1
- data/lib/imagecache/url_writer.rb +3 -1
- data/lib/imagecache/version.rb +3 -1
- data/spec/backend/filesystem_spec.rb +38 -0
- data/spec/public/imagecache/images/placeholder.jpg +0 -0
- data/spec/public/images/sunset.jpg +0 -0
- data/spec/spec_helper.rb +17 -0
- metadata +18 -28
- data/test/filesystem_backend_test.rb +0 -43
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
imagecache (0.0.
|
4
|
+
imagecache (0.0.3)
|
5
5
|
activesupport (~> 4.0, >= 4.0)
|
6
6
|
aws-sdk (~> 1.60.2, >= 1.60.2)
|
7
7
|
redis (~> 3.0, >= 3.0)
|
@@ -9,17 +9,23 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (4.2.
|
12
|
+
activesupport (4.2.7.1)
|
13
13
|
i18n (~> 0.7)
|
14
14
|
json (~> 1.7, >= 1.7.7)
|
15
15
|
minitest (~> 5.1)
|
16
16
|
thread_safe (~> 0.3, >= 0.3.4)
|
17
17
|
tzinfo (~> 1.1)
|
18
|
+
ast (2.3.0)
|
18
19
|
aws-sdk (1.60.2)
|
19
20
|
aws-sdk-v1 (= 1.60.2)
|
20
21
|
aws-sdk-v1 (1.60.2)
|
21
22
|
json (~> 1.4)
|
22
23
|
nokogiri (>= 1.4.4)
|
24
|
+
benchmark-perf (0.1.0)
|
25
|
+
codeclimate-test-reporter (0.6.0)
|
26
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
27
|
+
diff-lcs (1.2.5)
|
28
|
+
docile (1.1.5)
|
23
29
|
i18n (0.7.0)
|
24
30
|
json (1.8.3)
|
25
31
|
mini_portile2 (2.1.0)
|
@@ -27,20 +33,63 @@ GEM
|
|
27
33
|
nokogiri (1.6.8)
|
28
34
|
mini_portile2 (~> 2.1.0)
|
29
35
|
pkg-config (~> 1.1.7)
|
36
|
+
parser (2.3.1.4)
|
37
|
+
ast (~> 2.2)
|
30
38
|
pkg-config (1.1.7)
|
39
|
+
powerpack (0.1.1)
|
40
|
+
rainbow (2.1.0)
|
31
41
|
rake (11.3.0)
|
32
42
|
redis (3.3.1)
|
43
|
+
roo (2.4.0)
|
44
|
+
nokogiri (~> 1)
|
45
|
+
rubyzip (~> 1.1, < 2.0.0)
|
46
|
+
rspec (3.5.0)
|
47
|
+
rspec-core (~> 3.5.0)
|
48
|
+
rspec-expectations (~> 3.5.0)
|
49
|
+
rspec-mocks (~> 3.5.0)
|
50
|
+
rspec-benchmark (0.1.0)
|
51
|
+
benchmark-perf (~> 0.1.0)
|
52
|
+
rspec (>= 3.0.0, < 4.0.0)
|
53
|
+
rspec-core (3.5.4)
|
54
|
+
rspec-support (~> 3.5.0)
|
55
|
+
rspec-expectations (3.5.0)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.5.0)
|
58
|
+
rspec-mocks (3.5.0)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.5.0)
|
61
|
+
rspec-support (3.5.0)
|
62
|
+
rubocop (0.44.1)
|
63
|
+
parser (>= 2.3.1.1, < 3.0)
|
64
|
+
powerpack (~> 0.1)
|
65
|
+
rainbow (>= 1.99.1, < 3.0)
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
68
|
+
ruby-progressbar (1.8.1)
|
69
|
+
rubyzip (1.2.0)
|
70
|
+
simplecov (0.12.0)
|
71
|
+
docile (~> 1.1.0)
|
72
|
+
json (>= 1.8, < 3)
|
73
|
+
simplecov-html (~> 0.10.0)
|
74
|
+
simplecov-html (0.10.0)
|
75
|
+
sqlite3 (1.3.12)
|
33
76
|
thread_safe (0.3.5)
|
34
77
|
tzinfo (1.2.2)
|
35
78
|
thread_safe (~> 0.1)
|
79
|
+
unicode-display_width (1.1.1)
|
36
80
|
|
37
81
|
PLATFORMS
|
38
82
|
ruby
|
39
83
|
|
40
84
|
DEPENDENCIES
|
85
|
+
codeclimate-test-reporter
|
41
86
|
imagecache!
|
42
|
-
|
43
|
-
|
87
|
+
rake
|
88
|
+
roo (~> 2.4.0)
|
89
|
+
rspec (>= 2.0)
|
90
|
+
rspec-benchmark
|
91
|
+
rubocop
|
92
|
+
sqlite3
|
44
93
|
|
45
94
|
BUNDLED WITH
|
46
|
-
1.13.
|
95
|
+
1.13.4
|
data/README.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
# Imagecache
|
2
2
|
An image cropping and caching library written in Ruby
|
3
3
|
|
4
|
+
<table>
|
5
|
+
<tr>
|
6
|
+
<td>Build Status</td>
|
7
|
+
<td>
|
8
|
+
<a href="https://circleci.com/gh/thinktopography/imagecache">
|
9
|
+
<img src="https://img.shields.io/circleci/project/thinktopography/imagecache.svg?maxAge=600" alt="Build Status" >
|
10
|
+
</a>
|
11
|
+
</td>
|
12
|
+
</tr>
|
13
|
+
<tr>
|
14
|
+
<td>Code Quality</td>
|
15
|
+
<td>
|
16
|
+
<a href="https://codeclimate.com/github/thinktopography/imagecache">
|
17
|
+
<img src="https://img.shields.io/codeclimate/github/thinktopography/imagecache.svg?maxAge=600" alt="Code Climate" />
|
18
|
+
</a>
|
19
|
+
<a href="https://codeclimate.com/github/thinktopography/imagecache/coverage">
|
20
|
+
<img src="https://img.shields.io/codeclimate/coverage/github/thinktopography/imagecache.svg?maxAge=600" alt="Code Coverage" />
|
21
|
+
</a>
|
22
|
+
</td>
|
23
|
+
</tr>
|
24
|
+
</table>
|
4
25
|
## Installation
|
5
26
|
|
6
27
|
```sh
|
@@ -19,8 +40,7 @@ In your controller:
|
|
19
40
|
class ImagecacheController < ApplicationController
|
20
41
|
|
21
42
|
def show
|
22
|
-
|
23
|
-
if image = imagecache.process(params[:permalink])
|
43
|
+
if image = Imagecache::Base.process(params[:permalink])
|
24
44
|
redirect_to params[:permalink], status: 301
|
25
45
|
else
|
26
46
|
render text: '', status: 404
|
data/Rakefile
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
-
require 'rake/testtask'
|
3
2
|
require 'bundler/version'
|
4
3
|
require './lib/imagecache'
|
5
4
|
require './lib/imagecache/version'
|
5
|
+
require 'rspec/core/rake_task'
|
6
6
|
|
7
|
-
|
8
|
-
t.libs << '.' << 'lib' << 'test'
|
9
|
-
t.test_files = FileList['test/*_test.rb']
|
10
|
-
t.verbose = false
|
11
|
-
end
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
8
|
|
13
9
|
desc "Build the gem"
|
14
10
|
task :build do
|
data/circle.yml
ADDED
data/imagecache.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
gem.add_development_dependency 'rake', '~> 11.3.0', '>= 11.3.0'
|
20
|
-
gem.add_development_dependency 'minitest', '~> 5.9.1', '>= 5.9.1'
|
21
20
|
gem.add_runtime_dependency 'activesupport', '~> 4.0', '>= 4.0'
|
22
21
|
gem.add_runtime_dependency 'redis', '~> 3.0', '>= 3.0'
|
23
22
|
gem.add_runtime_dependency 'aws-sdk', '~> 1.60.2', '>= 1.60.2'
|
data/lib/imagecache.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Imagecache
|
4
|
-
require 'imagecache/
|
5
|
-
require 'imagecache/
|
6
|
-
require 'imagecache/
|
4
|
+
require 'imagecache/backend/filesystem'
|
5
|
+
require 'imagecache/backend/redis'
|
6
|
+
require 'imagecache/backend/s3'
|
7
7
|
require 'imagecache/conversions/crop'
|
8
8
|
require 'imagecache/conversions/fit'
|
9
9
|
require 'imagecache/conversions/resize'
|
@@ -13,4 +13,4 @@ module Imagecache
|
|
13
13
|
require 'imagecache/converter'
|
14
14
|
require 'imagecache/url_reader'
|
15
15
|
require 'imagecache/url_writer'
|
16
|
-
end
|
16
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Imagecache
|
4
|
-
|
4
|
+
|
5
|
+
module Backend
|
6
|
+
|
5
7
|
class Filesystem
|
6
8
|
|
7
9
|
def initialize(root = nil)
|
@@ -36,10 +38,10 @@ module Imagecache
|
|
36
38
|
|
37
39
|
def mkdir(filepath)
|
38
40
|
directories = File.dirname(filepath).split("/").drop(1)
|
39
|
-
fullpath =
|
41
|
+
fullpath = @root
|
40
42
|
directories.each do |directory|
|
41
43
|
fullpath += "/#{directory}"
|
42
|
-
if !Dir.
|
44
|
+
if !Dir.exist?(fullpath)
|
43
45
|
Dir.mkdir(fullpath)
|
44
46
|
end
|
45
47
|
end
|
@@ -57,5 +59,7 @@ module Imagecache
|
|
57
59
|
end
|
58
60
|
|
59
61
|
end
|
62
|
+
|
60
63
|
end
|
61
|
-
|
64
|
+
|
65
|
+
end
|
data/lib/imagecache/base.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Imagecache
|
4
|
+
|
4
5
|
class Base
|
5
6
|
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def build(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(path)
|
13
|
+
new.process(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
6
18
|
def process(path)
|
7
19
|
url = url_reader.read(path)
|
8
|
-
if original = source(url.assetpath)
|
9
|
-
if converted = converter.convert(original, url.conversions)
|
20
|
+
if (original = source(url.assetpath))
|
21
|
+
if (converted = converter.convert(original, url.conversions))
|
10
22
|
newurl = url_writer.write(url.conversions, url.assetpath)
|
11
23
|
filesystem.set(newurl, converted.data)
|
12
24
|
return converted
|
@@ -40,12 +52,13 @@ module Imagecache
|
|
40
52
|
end
|
41
53
|
|
42
54
|
def filesystem
|
43
|
-
@filesystem ||= Imagecache::
|
55
|
+
@filesystem ||= Imagecache::Backend::Filesystem.new
|
44
56
|
end
|
45
57
|
|
46
58
|
def s3
|
47
|
-
@s3 ||= Imagecache::
|
59
|
+
@s3 ||= Imagecache::Backend::S3.new
|
48
60
|
end
|
49
61
|
|
50
62
|
end
|
63
|
+
|
51
64
|
end
|
@@ -1,20 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Imagecache
|
4
|
+
|
4
5
|
module Conversions
|
6
|
+
|
5
7
|
class Resize
|
6
8
|
|
7
|
-
def process(file,
|
9
|
+
def process(file, _metadata, conversion)
|
8
10
|
width = conversion.width
|
9
11
|
height = conversion.height
|
10
12
|
command = "convert #{file.path} -resize #{width}x#{height} #{file.path}"
|
11
|
-
|
12
|
-
output = `#{command}`
|
13
|
+
`#{command}`
|
13
14
|
data = File.open(file.path).read
|
14
15
|
File.unlink(file.path)
|
15
16
|
data
|
16
17
|
end
|
17
18
|
|
18
19
|
end
|
20
|
+
|
19
21
|
end
|
20
|
-
|
22
|
+
|
23
|
+
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Imagecache
|
4
|
+
|
4
5
|
module Conversions
|
6
|
+
|
5
7
|
class Round
|
6
8
|
|
7
9
|
def process(file, metadata, conversion)
|
8
10
|
shortest = [metadata.width, metadata.height].min
|
9
|
-
Rails.logger.debug(conversion.radius)
|
10
|
-
Rails.logger.debug(shortest)
|
11
11
|
radius = (conversion.radius / 100.to_f) * shortest
|
12
12
|
command = command(file.path, radius)
|
13
|
-
|
14
|
-
output = `#{command}`
|
13
|
+
`#{command}`
|
15
14
|
data = File.open("#{file.path}.png").read
|
16
15
|
File.unlink("#{file.path}.png")
|
17
16
|
File.unlink(file.path)
|
@@ -31,5 +30,7 @@ module Imagecache
|
|
31
30
|
end
|
32
31
|
|
33
32
|
end
|
33
|
+
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
|
+
end
|
data/lib/imagecache/converter.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Imagecache
|
4
|
+
|
4
5
|
class Converter
|
5
6
|
|
6
7
|
def convert(data, conversions)
|
7
|
-
(1..conversions.length).each do
|
8
|
+
(1..conversions.length).each do
|
8
9
|
data = _convert(assetpath, conversions)
|
9
10
|
end
|
10
11
|
file = file(data)
|
@@ -63,6 +64,6 @@ module Imagecache
|
|
63
64
|
@identify ||= Imagecache::Identify.new
|
64
65
|
end
|
65
66
|
|
66
|
-
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
|
+
end
|
data/lib/imagecache/identify.rb
CHANGED