photo-cook 1.1.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +16 -0
- data/Gemfile +3 -13
- data/README.md +2 -2
- data/Rakefile +2 -15
- data/app/assets/javascripts/photo-cook/photo-cook.coffee +90 -0
- data/app/helpers/photo_cook_helper.rb +14 -0
- data/lib/photo-cook/device-pixel-ratio-spy.rb +17 -0
- data/lib/photo-cook/device-pixel-ratio.rb +67 -0
- data/lib/photo-cook/engine.rb +15 -2
- data/lib/photo-cook/events.rb +15 -0
- data/lib/photo-cook/logger.rb +37 -0
- data/lib/photo-cook/optimization/__api__.rb +21 -0
- data/lib/photo-cook/optimization/carrierwave.rb +10 -0
- data/lib/photo-cook/optimization/image-optim.rb +131 -0
- data/lib/photo-cook/optimization/job.rb +12 -0
- data/lib/photo-cook/optimization/logging.rb +21 -0
- data/lib/photo-cook/pixels.rb +56 -0
- data/lib/photo-cook/resize/__api__.rb +93 -0
- data/lib/photo-cook/resize/assemble.rb +125 -0
- data/lib/photo-cook/resize/calculations.rb +63 -0
- data/lib/photo-cook/resize/carrierwave.rb +22 -0
- data/lib/photo-cook/resize/command.rb +28 -0
- data/lib/photo-cook/resize/logging.rb +25 -0
- data/lib/photo-cook/resize/magick-photo.rb +34 -0
- data/lib/photo-cook/resize/middleware.rb +108 -0
- data/lib/photo-cook/resize/mode.rb +36 -0
- data/lib/photo-cook/resize/resizer.rb +88 -0
- data/lib/photo-cook/utils.rb +71 -0
- data/lib/photo-cook/version.rb +3 -2
- data/lib/photo-cook.rb +32 -23
- data/photo-cook.gemspec +14 -8
- data/srcset.rb +34 -0
- data/test/fixtures/dog.png +0 -0
- data/test/helper.rb +12 -0
- data/test/test-photo-cook-assemble.rb +23 -0
- data/test/test-photo-cook-calculations.rb +45 -0
- data/test/test-photo-cook-resize.rb +62 -0
- metadata +86 -25
- data/app/assets/javascripts/photo-cook/photo-cook.js.erb +0 -85
- data/lib/photo-cook/abstract-optimizer.rb +0 -9
- data/lib/photo-cook/assemble.rb +0 -97
- data/lib/photo-cook/carrierwave.rb +0 -15
- data/lib/photo-cook/command.rb +0 -49
- data/lib/photo-cook/dimensions.rb +0 -36
- data/lib/photo-cook/dirs.rb +0 -8
- data/lib/photo-cook/image-optim.rb +0 -24
- data/lib/photo-cook/logging.rb +0 -85
- data/lib/photo-cook/magick-photo.rb +0 -6
- data/lib/photo-cook/middleware.rb +0 -139
- data/lib/photo-cook/optimization-api.rb +0 -20
- data/lib/photo-cook/optimization-job.rb +0 -9
- data/lib/photo-cook/pixel-ratio-spy.rb +0 -19
- data/lib/photo-cook/pixel-ratio.rb +0 -36
- data/lib/photo-cook/resize-api.rb +0 -94
- data/lib/photo-cook/resizer.rb +0 -111
- data/lib/photo-cook/size-formatting.rb +0 -13
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module PhotoCook
|
3
|
+
module Utils
|
4
|
+
class << self
|
5
|
+
def format_size(bytes, precision = 2)
|
6
|
+
if bytes >= 1_000_000_000.0
|
7
|
+
"#{(bytes / 1_000_000_000.0).round(precision)} GB"
|
8
|
+
|
9
|
+
elsif bytes >= 1_000_000.0
|
10
|
+
"#{(bytes / 1_000_000.0).round(precision)} MB"
|
11
|
+
|
12
|
+
else
|
13
|
+
"#{(bytes / 1_000.0).round(precision)} KB"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def call_block_with_floating_arguments(callable, args)
|
18
|
+
arity = callable.arity
|
19
|
+
resized_args = arity < 0 ? args : args[0...arity]
|
20
|
+
callable.call(*resized_args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_relative_symlink(source, destination)
|
24
|
+
unless File.readable?(destination)
|
25
|
+
# /application/public/resize-cache/uploads/photos/1
|
26
|
+
p1 = source.kind_of?(String) ? Pathname.new(source) : source
|
27
|
+
|
28
|
+
# /application/public/uploads/photos/1/resize-cache
|
29
|
+
p2 = destination.kind_of?(String) ? Pathname.new(destination) : destination
|
30
|
+
|
31
|
+
# ../../../resize-cache/uploads/photos/1
|
32
|
+
relative = p1.relative_path_from(p2.dirname).to_s
|
33
|
+
|
34
|
+
# resize-cache
|
35
|
+
basename = p2.basename.to_s
|
36
|
+
|
37
|
+
flags = symlink_utility_needs_relative_flag? ? '-rs' : '-s'
|
38
|
+
cmd = "cd #{p2.dirname.to_s} && rm -f #{basename} && ln #{flags} #{relative} #{basename}"
|
39
|
+
|
40
|
+
%x{ #{cmd} }
|
41
|
+
|
42
|
+
PhotoCook.log do
|
43
|
+
log "Symlink"
|
44
|
+
log "Source: #{p1.to_s}"
|
45
|
+
log "Destination: #{p2.to_s}"
|
46
|
+
log "Command: #{cmd}"
|
47
|
+
log "Status: #{$?.success? ? 'OK' : 'FAIL'}"
|
48
|
+
end
|
49
|
+
|
50
|
+
return $?.success?
|
51
|
+
end
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def symlink_utility_needs_relative_flag?
|
56
|
+
if @relative_flag_illegal.nil?
|
57
|
+
out = Open3.capture2e('ln', '-rs')[0]
|
58
|
+
@relative_flag_illegal = !!(out =~ /\billegal\b/)
|
59
|
+
end
|
60
|
+
@relative_flag_illegal == false
|
61
|
+
end
|
62
|
+
|
63
|
+
def measure
|
64
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
65
|
+
returned = yield
|
66
|
+
finished = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
67
|
+
[returned, finished - started]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/photo-cook/version.rb
CHANGED
data/lib/photo-cook.rb
CHANGED
@@ -1,33 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'fileutils'
|
2
3
|
require 'pathname'
|
4
|
+
require 'open3'
|
5
|
+
require 'base64'
|
6
|
+
require 'pathname'
|
7
|
+
require 'logger'
|
3
8
|
require 'rake'
|
4
9
|
require 'mini_magick'
|
5
|
-
require '
|
10
|
+
require 'os'
|
6
11
|
|
7
12
|
module PhotoCook
|
8
|
-
|
9
|
-
|
13
|
+
class << self
|
14
|
+
attr_accessor :root_path, :public_dir
|
10
15
|
end
|
16
|
+
self.public_dir = 'public'
|
11
17
|
end
|
12
18
|
|
13
|
-
require 'photo-cook/
|
14
|
-
require 'photo-cook/
|
15
|
-
require 'photo-cook/
|
16
|
-
require 'photo-cook/
|
17
|
-
require 'photo-cook/
|
18
|
-
require 'photo-cook/
|
19
|
-
require 'photo-cook/resizer'
|
20
|
-
require 'photo-cook/middleware'
|
21
|
-
require 'photo-cook/magick-photo'
|
22
|
-
require 'photo-cook/carrierwave'
|
23
|
-
require 'photo-cook/abstract-optimizer'
|
24
|
-
require 'photo-cook/image-optim'
|
25
|
-
require 'photo-cook/resize-api'
|
26
|
-
require 'photo-cook/optimization-api'
|
27
|
-
require 'photo-cook/size-formatting'
|
19
|
+
require 'photo-cook/utils'
|
20
|
+
require 'photo-cook/logger'
|
21
|
+
require 'photo-cook/events'
|
22
|
+
require 'photo-cook/pixels'
|
23
|
+
require 'photo-cook/device-pixel-ratio'
|
24
|
+
require 'photo-cook/device-pixel-ratio-spy' if defined?(Rails)
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
require 'photo-cook/resize/__api__'
|
27
|
+
require 'photo-cook/resize/assemble'
|
28
|
+
require 'photo-cook/resize/calculations'
|
29
|
+
require 'photo-cook/resize/carrierwave'
|
30
|
+
require 'photo-cook/resize/command'
|
31
|
+
require 'photo-cook/resize/magick-photo'
|
32
|
+
require 'photo-cook/resize/middleware'
|
33
|
+
require 'photo-cook/resize/mode'
|
34
|
+
require 'photo-cook/resize/resizer'
|
35
|
+
require 'photo-cook/resize/logging'
|
36
|
+
|
37
|
+
require 'photo-cook/optimization/__api__'
|
38
|
+
require 'photo-cook/optimization/job' if defined?(ActiveJob)
|
39
|
+
require 'photo-cook/optimization/carrierwave'
|
40
|
+
require 'photo-cook/optimization/logging'
|
41
|
+
|
42
|
+
require 'photo-cook/engine' if defined?(Rails)
|
data/photo-cook.gemspec
CHANGED
@@ -1,21 +1,27 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
require File.expand_path('../lib/photo-cook/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'photo-cook'
|
6
6
|
s.version = PhotoCook::VERSION
|
7
7
|
s.authors = ['Yaroslav Konoplov']
|
8
|
-
s.email = ['
|
8
|
+
s.email = ['eahome00@gmail.com']
|
9
9
|
s.homepage = 'http://github.com/yivo/photo-cook'
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
# TODO Write better summary and description
|
12
|
+
s.summary = 'Tool for resizing and optimizing photos in Ruby'
|
13
|
+
s.description = 'This gem provides complete tool for resizing and optimizing photos in Ruby'
|
12
14
|
s.license = 'MIT'
|
13
15
|
|
14
|
-
s.executables = `git ls-files -z -- bin/*`.split("\x0").map{ |f| File.basename(f) }
|
16
|
+
s.executables = `git ls-files -z -- bin/*`.split("\x0").map { |f| File.basename(f) }
|
15
17
|
s.files = `git ls-files -z`.split("\x0")
|
16
18
|
s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
|
17
|
-
s.require_paths =
|
19
|
+
s.require_paths = %w( app lib )
|
18
20
|
|
19
|
-
s.add_dependency 'rack',
|
21
|
+
s.add_dependency 'rack', '~> 1.5'
|
20
22
|
s.add_dependency 'mini_magick', '~> 4.0'
|
21
|
-
|
23
|
+
s.add_dependency 'os', '~> 0.9'
|
24
|
+
|
25
|
+
s.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
end
|
data/srcset.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# def test_something
|
3
|
+
# def lol(maxw, maxh, w, h)
|
4
|
+
# ary = []
|
5
|
+
#
|
6
|
+
# w = w.floor
|
7
|
+
# maxw = maxw.floor
|
8
|
+
# # maxx = [maxw % 160 == 0 ? maxw : 160 * (1 + maxw / 160), (w*3) % 160 == 0 ? (w*3) : 160 * (1 + (w*3) / 160)].min
|
9
|
+
# maxx = [maxw, w * 3].min
|
10
|
+
#
|
11
|
+
# x = 320
|
12
|
+
# ary << [w, h] if w < x
|
13
|
+
#
|
14
|
+
# while x <= maxx
|
15
|
+
# inc = x / w.to_f
|
16
|
+
# ary << [(w * inc).floor, (h * inc).floor]
|
17
|
+
#
|
18
|
+
# if w > x && w < (x + 160)
|
19
|
+
# ary << [w, h]
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# x += 160
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# ary
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# puts
|
29
|
+
# puts lol(1000, 800, 350, 350)
|
30
|
+
#
|
31
|
+
#
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# end
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda-context'
|
4
|
+
require 'photo-cook'
|
5
|
+
require 'helper'
|
6
|
+
|
7
|
+
class PhotoCookAssembleTest < Test::Unit::TestCase
|
8
|
+
def test_assemble
|
9
|
+
assert_equal('/uploads/resize-cache/fit-300x300/dog.png', PhotoCook::Resize.uri('/uploads/dog.png', 300, 300, :fit))
|
10
|
+
assert_equal('/uploads/resize-cache/fill-300x300/dog.png', PhotoCook::Resize.uri('/uploads/dog.png', 300, 300, :fill))
|
11
|
+
assert_equal('/uploads/photos/1/md5/resize-cache/fill-300x300/dog.png', PhotoCook::Resize.uri('/uploads/photos/1/md5/dog.png', 300, 300, :fill))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_strip
|
15
|
+
assert_equal('/uploads/dog.png', PhotoCook::Resize.strip('/uploads/resize-cache/fit-300x300/dog.png'))
|
16
|
+
assert_equal('/uploads/dog.png', PhotoCook::Resize.strip('/uploads/resize-cache/fill-300x300/dog.png'))
|
17
|
+
assert_equal('/uploads/photos/1/md5/dog.png', PhotoCook::Resize.strip('/uploads/photos/1/md5/resize-cache/fill-300x300/dog.png'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_is_resize_uri
|
21
|
+
assert_true(PhotoCook::Resize::Assemble.resize_uri?('/uploads/photos/1/resize-cache/fill-300x300/dog.png'))
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda-context'
|
4
|
+
require 'photo-cook'
|
5
|
+
|
6
|
+
class PhotoCookCalculationsTest < Test::Unit::TestCase
|
7
|
+
def test_size_to_fill_calculations
|
8
|
+
test_size_to_fill(1000, 800, 640, 640, [640, 640])
|
9
|
+
test_size_to_fill(1000, 800, 1280, 1280, [800, 800])
|
10
|
+
test_size_to_fill(1000, 800, 3840, 3840, [800, 800])
|
11
|
+
test_size_to_fill(1000, 800, 1000, 1280, [625, 800])
|
12
|
+
test_size_to_fill(1000, 800, 2000, 2560, [625, 800])
|
13
|
+
test_size_to_fill(264, 175, 400, 300, [233, 175])
|
14
|
+
test_size_to_fill(331, 277, 680, 360, [331, 175])
|
15
|
+
test_size_to_fill(259, 179, 260, 180, [258, 179])
|
16
|
+
test_size_to_fill(259, 179, 520, 360, [258, 179])
|
17
|
+
test_size_to_fill(455, 683, 800, 700, [455, 398])
|
18
|
+
test_size_to_fill(683, 455, 800, 700, [520, 455])
|
19
|
+
test_size_to_fill(444, 455, 1200, 1255, [435, 455])
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_size_to_fit_calculations
|
23
|
+
test_size_to_fit(400, 300, 200, 700, [200, 150])
|
24
|
+
test_size_to_fit(1920, 1200, 2560, 2560, [1920, 1200])
|
25
|
+
test_size_to_fit(2613, 3070, 1280, 1280, [1089, 1280])
|
26
|
+
test_size_to_fit(400, 800, 100, 340, [100, 200])
|
27
|
+
test_size_to_fit(600, 340, 2000, 2000, [600, 340])
|
28
|
+
test_size_to_fit(600, 340, 400, 100, [176, 100])
|
29
|
+
test_size_to_fit(600, 340, 400, 400, [400, 226])
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def assert_same_dimensions(d1, d2)
|
34
|
+
assert_same(d2[0], d1[0])
|
35
|
+
assert_same(d2[1], d1[1])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_size_to_fill(*calculation_args, expected_result)
|
39
|
+
assert_same_dimensions(PhotoCook::Resize::Calculations.size_to_fill(*calculation_args), expected_result)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_size_to_fit(*calculation_args, expected_result)
|
43
|
+
assert_same_dimensions(PhotoCook::Resize::Calculations.size_to_fit(*calculation_args), expected_result)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda-context'
|
4
|
+
require 'photo-cook'
|
5
|
+
require 'helper'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
Test::Unit.at_start { PhotoCook.disable_logging! }
|
9
|
+
Test::Unit.at_exit { FileUtils.rmtree(TestHelper.tmp_dirpath) }
|
10
|
+
|
11
|
+
class PhotoCookResizeTest < Test::Unit::TestCase
|
12
|
+
def test_resize_fit
|
13
|
+
source = File.join(TestHelper.fixtures_dirpath, 'dog.png')
|
14
|
+
store = File.join(TestHelper.tmp_dirpath, 'dog-200x200-fit.png')
|
15
|
+
PhotoCook::Resize.perform(source, store, 200, 200, :fit)
|
16
|
+
|
17
|
+
photo = MiniMagick::Image.open(store)
|
18
|
+
assert_nothing_raised { photo.validate! }
|
19
|
+
assert_equal(photo[:dimensions][0], 200)
|
20
|
+
assert_equal(photo[:dimensions][1], 186)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_resize_fit_high_resolution
|
24
|
+
source = File.join(TestHelper.fixtures_dirpath, 'dog.png')
|
25
|
+
store = File.join(TestHelper.tmp_dirpath, 'dog-1000x1000-fit.png')
|
26
|
+
PhotoCook::Resize.perform(source, store, 1000, 1000, :fit)
|
27
|
+
|
28
|
+
photo = MiniMagick::Image.open(store)
|
29
|
+
assert_nothing_raised { photo.validate! }
|
30
|
+
assert_equal(photo[:dimensions][0], 800)
|
31
|
+
assert_equal(photo[:dimensions][1], 745)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_resize_fill
|
35
|
+
source = File.join(TestHelper.fixtures_dirpath, 'dog.png')
|
36
|
+
store = File.join(TestHelper.tmp_dirpath, 'dog-200x200-fill.png')
|
37
|
+
PhotoCook::Resize.perform(source, store, 200, 200, :fill)
|
38
|
+
|
39
|
+
photo = MiniMagick::Image.open(store)
|
40
|
+
assert_nothing_raised { photo.validate! }
|
41
|
+
assert_equal(photo[:dimensions][0], 200)
|
42
|
+
assert_equal(photo[:dimensions][1], 200)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_resize_fill_high_resolution
|
46
|
+
source = File.join(TestHelper.fixtures_dirpath, 'dog.png')
|
47
|
+
store = File.join(TestHelper.tmp_dirpath, 'dog-1000x1000-fill.png')
|
48
|
+
PhotoCook::Resize.perform(source, store, 1000, 1000, :fill)
|
49
|
+
|
50
|
+
photo = MiniMagick::Image.open(store)
|
51
|
+
assert_nothing_raised { photo.validate! }
|
52
|
+
assert_equal(photo[:dimensions][0], 745)
|
53
|
+
assert_equal(photo[:dimensions][1], 745)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_resize_base64
|
57
|
+
source = File.join(TestHelper.fixtures_dirpath, 'dog.png')
|
58
|
+
store = File.join(TestHelper.tmp_dirpath, 'dog-10x10-fit.png')
|
59
|
+
base64 = PhotoCook::Resize::base64_uri_from_source_path(source, store, 10, 10, :fit)
|
60
|
+
assert_match(/data:image\/png;base64,/, base64)
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: photo-cook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,40 +38,95 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: os
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: This gem provides complete tool for resizing and optimizing photos in
|
84
|
+
Ruby
|
42
85
|
email:
|
43
|
-
-
|
86
|
+
- eahome00@gmail.com
|
44
87
|
executables: []
|
45
88
|
extensions: []
|
46
89
|
extra_rdoc_files: []
|
47
90
|
files:
|
48
91
|
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
49
93
|
- Gemfile
|
50
94
|
- README.md
|
51
95
|
- Rakefile
|
52
96
|
- app/assets/javascripts/photo-cook.js
|
53
|
-
- app/assets/javascripts/photo-cook/photo-cook.
|
97
|
+
- app/assets/javascripts/photo-cook/photo-cook.coffee
|
98
|
+
- app/helpers/photo_cook_helper.rb
|
54
99
|
- lib/photo-cook.rb
|
55
|
-
- lib/photo-cook/
|
56
|
-
- lib/photo-cook/
|
57
|
-
- lib/photo-cook/carrierwave.rb
|
58
|
-
- lib/photo-cook/command.rb
|
59
|
-
- lib/photo-cook/dimensions.rb
|
60
|
-
- lib/photo-cook/dirs.rb
|
100
|
+
- lib/photo-cook/device-pixel-ratio-spy.rb
|
101
|
+
- lib/photo-cook/device-pixel-ratio.rb
|
61
102
|
- lib/photo-cook/engine.rb
|
62
|
-
- lib/photo-cook/
|
63
|
-
- lib/photo-cook/
|
64
|
-
- lib/photo-cook/
|
65
|
-
- lib/photo-cook/
|
66
|
-
- lib/photo-cook/optimization-
|
67
|
-
- lib/photo-cook/optimization
|
68
|
-
- lib/photo-cook/
|
69
|
-
- lib/photo-cook/
|
70
|
-
- lib/photo-cook/resize
|
71
|
-
- lib/photo-cook/
|
72
|
-
- lib/photo-cook/
|
103
|
+
- lib/photo-cook/events.rb
|
104
|
+
- lib/photo-cook/logger.rb
|
105
|
+
- lib/photo-cook/optimization/__api__.rb
|
106
|
+
- lib/photo-cook/optimization/carrierwave.rb
|
107
|
+
- lib/photo-cook/optimization/image-optim.rb
|
108
|
+
- lib/photo-cook/optimization/job.rb
|
109
|
+
- lib/photo-cook/optimization/logging.rb
|
110
|
+
- lib/photo-cook/pixels.rb
|
111
|
+
- lib/photo-cook/resize/__api__.rb
|
112
|
+
- lib/photo-cook/resize/assemble.rb
|
113
|
+
- lib/photo-cook/resize/calculations.rb
|
114
|
+
- lib/photo-cook/resize/carrierwave.rb
|
115
|
+
- lib/photo-cook/resize/command.rb
|
116
|
+
- lib/photo-cook/resize/logging.rb
|
117
|
+
- lib/photo-cook/resize/magick-photo.rb
|
118
|
+
- lib/photo-cook/resize/middleware.rb
|
119
|
+
- lib/photo-cook/resize/mode.rb
|
120
|
+
- lib/photo-cook/resize/resizer.rb
|
121
|
+
- lib/photo-cook/utils.rb
|
73
122
|
- lib/photo-cook/version.rb
|
74
123
|
- photo-cook.gemspec
|
124
|
+
- srcset.rb
|
125
|
+
- test/fixtures/dog.png
|
126
|
+
- test/helper.rb
|
127
|
+
- test/test-photo-cook-assemble.rb
|
128
|
+
- test/test-photo-cook-calculations.rb
|
129
|
+
- test/test-photo-cook-resize.rb
|
75
130
|
homepage: http://github.com/yivo/photo-cook
|
76
131
|
licenses:
|
77
132
|
- MIT
|
@@ -79,6 +134,7 @@ metadata: {}
|
|
79
134
|
post_install_message:
|
80
135
|
rdoc_options: []
|
81
136
|
require_paths:
|
137
|
+
- app
|
82
138
|
- lib
|
83
139
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
140
|
requirements:
|
@@ -92,8 +148,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
148
|
version: '0'
|
93
149
|
requirements: []
|
94
150
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.5.1
|
96
152
|
signing_key:
|
97
153
|
specification_version: 4
|
98
|
-
summary:
|
99
|
-
test_files:
|
154
|
+
summary: Tool for resizing and optimizing photos in Ruby
|
155
|
+
test_files:
|
156
|
+
- test/fixtures/dog.png
|
157
|
+
- test/helper.rb
|
158
|
+
- test/test-photo-cook-assemble.rb
|
159
|
+
- test/test-photo-cook-calculations.rb
|
160
|
+
- test/test-photo-cook-resize.rb
|
@@ -1,85 +0,0 @@
|
|
1
|
-
(function(root) {
|
2
|
-
var PhotoCook = {
|
3
|
-
cacheDir: <%= PhotoCook.cache_dir.to_json %>,
|
4
|
-
|
5
|
-
commandRegex: /^$width=auto|\d{1,5}&height=auto|\d{1,5}&pixel_ratio=[1234]&crop=yes|no$/,
|
6
|
-
|
7
|
-
initialize: function() {
|
8
|
-
PhotoCook.persistPixelRatio();
|
9
|
-
},
|
10
|
-
|
11
|
-
// Returns device pixel ratio (float)
|
12
|
-
// If no ratio could be determined will return normal ratio (1.0)
|
13
|
-
pixelRatio: (function () {
|
14
|
-
// https://gist.github.com/marcedwards/3446599
|
15
|
-
var mediaQuery = [
|
16
|
-
'(-webkit-min-device-pixel-ratio: 1.3)',
|
17
|
-
'(-o-min-device-pixel-ratio: 13/10)',
|
18
|
-
'min-resolution: 120dpi'
|
19
|
-
].join(', ');
|
20
|
-
|
21
|
-
var ratio = window.devicePixelRatio;
|
22
|
-
|
23
|
-
// If no ratio found check if screen is retina
|
24
|
-
// and if so return 2x ratio
|
25
|
-
if (ratio == null && typeof window.matchMedia === 'function') {
|
26
|
-
if (window.matchMedia(mediaQuery).matches) {
|
27
|
-
ratio = 2.0;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
return parseFloat(ratio) || 1.0;
|
32
|
-
})(),
|
33
|
-
|
34
|
-
persistPixelRatio: function() {
|
35
|
-
var date = new Date();
|
36
|
-
|
37
|
-
// Expires in 1 year
|
38
|
-
date.setTime(date.getTime() + 365 * 24 * 60 * 60 * 1000);
|
39
|
-
var expires = 'expires=' + date.toUTCString();
|
40
|
-
document.cookie = 'PhotoCookPixelRatio=' + PhotoCook.pixelRatio + '; ' + expires;
|
41
|
-
},
|
42
|
-
|
43
|
-
resize: function (path, width, height, options) {
|
44
|
-
var crop = typeof options === 'boolean' ? !!options : !!(options && options.crop);
|
45
|
-
var ratio = Math.ceil(Math.max(0, options && options.pixelRatio) || PhotoCook.pixelRatio);
|
46
|
-
var command = 'width=' + (+width || 'auto') +
|
47
|
-
'&height=' + (+height || 'auto') +
|
48
|
-
'&pixel_ratio=' + (+ratio || 1) +
|
49
|
-
'&crop=' + (crop ? 'yes' : 'no');
|
50
|
-
var els = path.split('/');
|
51
|
-
els.splice(-1, 0, PhotoCook.cacheDir, command);
|
52
|
-
return els.join('/');
|
53
|
-
},
|
54
|
-
|
55
|
-
strip: function (uri) {
|
56
|
-
var sections = uri.split('/');
|
57
|
-
var length = sections.length;
|
58
|
-
if (length < 3) { return uri; }
|
59
|
-
|
60
|
-
var cacheDir = sections[length - 3];
|
61
|
-
var command = sections[length - 2];
|
62
|
-
|
63
|
-
if (PhotoCook.cacheDir !== cacheDir || PhotoCook.commandRegex.test(command) == false) {
|
64
|
-
return uri;
|
65
|
-
}
|
66
|
-
|
67
|
-
sections.splice(length - 3, 2)
|
68
|
-
return sections.join('/');
|
69
|
-
},
|
70
|
-
|
71
|
-
uriRegex: /^[-a-z]+:\/\/|^(?:cid|data):|^\/\//i,
|
72
|
-
|
73
|
-
// Returns true if given URL can produce request to PhotoCook middleware on server
|
74
|
-
isServableURL: function(url) {
|
75
|
-
// By default check that URL is relative
|
76
|
-
return !PhotoCook.uriRegex.test(url);
|
77
|
-
}
|
78
|
-
};
|
79
|
-
|
80
|
-
root.PhotoCook = PhotoCook;
|
81
|
-
})(this);
|
82
|
-
|
83
|
-
PhotoCook.initialize();
|
84
|
-
|
85
|
-
// navigator.cookieEnabled
|