dzt 0.1.0 → 0.2.0
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.
- data/CHANGELOG.md +7 -0
- data/README.md +15 -1
- data/RELEASING.md +65 -0
- data/bin/dzt +31 -2
- data/lib/dzt/file_storage.rb +27 -0
- data/lib/dzt/s3_storage.rb +49 -0
- data/lib/dzt/tiler.rb +16 -14
- data/lib/dzt/version.rb +1 -1
- metadata +23 -11
- checksums.yaml +0 -7
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
### Next
|
|
2
|
+
|
|
3
|
+
### 0.2.0 (10/20/2014)
|
|
4
|
+
|
|
5
|
+
* [#7](https://github.com/dblock/dzt/pull/7): Added support for storing tiles in AWS S3 and exposed all tiler and storage options via command line - [@mzikherman](https://github.com/mzikherman).
|
|
6
|
+
* [#5](https://github.com/dblock/dzt/pull/5): Allow a Fog::Storage uploader to be passed in for uploading of generated tiles rather than local storage - [@mzikherman](https://github.com/mzikherman).
|
|
7
|
+
|
|
1
8
|
### 0.1.0 (3/16/2014)
|
|
2
9
|
|
|
3
10
|
* Initial public release - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
|
@@ -25,7 +25,21 @@ dzt help
|
|
|
25
25
|
dzt slice image.jpg --output tiles
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Creates a *tiles* folder with deep-zoom tiles.
|
|
28
|
+
Creates a *tiles* folder with deep-zoom tiles. This will use the defaults defined in [/lib/dzt/tiler.rb](/lib/dzt/tiler.rb#L7-L10).
|
|
29
|
+
|
|
30
|
+
You can pass in flags to override all these options, such as:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
dzt slice image.jpg --output=tiles --format=90 --tile-format=png
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Additionally, you can have generated files uploaded to S3 for you. You can specify that like:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
dzt slice image.jpg --acl=public-read --bucket=bucket --s3-key=prefix --aws-id=id --aws-secret=secret
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The files will be uploaded to the bucket specified, and generated files will be prefixed by the s3 key.
|
|
29
43
|
|
|
30
44
|
|
|
31
45
|
## Contributing
|
data/RELEASING.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Releasing Dzt
|
|
2
|
+
|
|
3
|
+
There're no particular rules about when to release dzt. Release bug fixes frequenty, features not so frequently and breaking API changes rarely.
|
|
4
|
+
|
|
5
|
+
### Release
|
|
6
|
+
|
|
7
|
+
Run tests, check that all tests succeed locally.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
bundle install
|
|
11
|
+
rake
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/dzt) for all supported platforms.
|
|
15
|
+
|
|
16
|
+
Increment the version, modify [lib/dzt/version.rb](lib/dzt/version.rb).
|
|
17
|
+
|
|
18
|
+
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.7.1` to `0.2.0`).
|
|
19
|
+
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.7.1` to `0.8.0`).
|
|
20
|
+
|
|
21
|
+
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
### 0.2.0 (14/10/2014)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
|
28
|
+
|
|
29
|
+
Commit your changes.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
git add CHANGELOG.md lib/dzt/version.rb
|
|
33
|
+
git commit -m "Preparing for release, 0.2.0."
|
|
34
|
+
git push origin master
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Release.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
$ rake release
|
|
41
|
+
|
|
42
|
+
dzt 0.2.0 built to pkg/dzt-0.2.0.gem.
|
|
43
|
+
Tagged v0.2.0.
|
|
44
|
+
Pushed git commits and tags.
|
|
45
|
+
Pushed dzt 0.2.0 to rubygems.org.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Prepare for the Next Version
|
|
49
|
+
|
|
50
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Next Release
|
|
54
|
+
============
|
|
55
|
+
|
|
56
|
+
* Your contribution here.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Comit your changes.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
git add CHANGELOG.md
|
|
63
|
+
git commit -m "Preparing for next release."
|
|
64
|
+
git push origin master
|
|
65
|
+
```
|
data/bin/dzt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require 'gli'
|
|
3
3
|
require 'dzt'
|
|
4
|
+
require 'fog'
|
|
4
5
|
|
|
5
6
|
include GLI::App
|
|
6
7
|
|
|
@@ -10,14 +11,42 @@ default_command :slice
|
|
|
10
11
|
|
|
11
12
|
desc "Slice an image"
|
|
12
13
|
command :slice do |c|
|
|
13
|
-
c.flag [:o, :output], desc: 'Output folder'
|
|
14
|
+
c.flag [:o, :output, 'output'], desc: 'Output folder'
|
|
15
|
+
c.flag [:ts, :tilesize, 'tile-size'], desc: 'Tile size', default_value: DZT::Tiler::DEFAULT_TILE_SIZE
|
|
16
|
+
c.flag [:to, :tileoverlap, 'tile-overlap'], desc: 'Tile overlap', default_value: DZT::Tiler::DEFAULT_TILE_OVERLAP
|
|
17
|
+
c.flag [:q, :quality], desc: 'Output quality', default_value: DZT::Tiler::DEFAULT_QUALITY
|
|
18
|
+
c.flag [:f, :format], desc: 'Tile format', default_value: DZT::Tiler::DEFAULT_TILE_FORMAT
|
|
19
|
+
c.flag [:overwrite], desc: 'Overwrite output files', default_value: DZT::Tiler::DEFAULT_OVERWRITE_FLAG
|
|
20
|
+
c.flag [:acl], desc: 'S3 Acl', default_value: DZT::S3Storage::DEFAULT_ACL
|
|
21
|
+
c.flag [:bucket], desc: 'S3 Bucket'
|
|
22
|
+
c.flag [:s3_key, 's3-key'], desc: 'S3 Key', default_value: DZT::S3Storage::DEFAULT_KEY
|
|
23
|
+
c.flag [:aws_id, 'aws-id'], desc: 'AWS Id'
|
|
24
|
+
c.flag [:aws_secret, 'aws-secret'], desc: 'AWS Secret'
|
|
14
25
|
c.action do |global_options, options, args|
|
|
15
26
|
if args.length < 1
|
|
16
27
|
raise 'You must specify an image file to slice.'
|
|
17
28
|
end
|
|
29
|
+
if options[:output]
|
|
30
|
+
storage = DZT::FileStorage.new(
|
|
31
|
+
destination: options[:output]
|
|
32
|
+
)
|
|
33
|
+
else
|
|
34
|
+
storage = DZT::S3Storage.new(
|
|
35
|
+
s3_acl: options[:acl],
|
|
36
|
+
s3_bucket: options[:bucket],
|
|
37
|
+
s3_key: options[:s3_key],
|
|
38
|
+
aws_id: options[:aws_id],
|
|
39
|
+
aws_secret: options[:aws_secret]
|
|
40
|
+
)
|
|
41
|
+
end
|
|
18
42
|
tiler = DZT::Tiler.new(
|
|
19
43
|
source: args[0],
|
|
20
|
-
|
|
44
|
+
size: options[:tilesize],
|
|
45
|
+
overlap: options[:tileoverlap],
|
|
46
|
+
format: options[:format],
|
|
47
|
+
quality: options[:quality],
|
|
48
|
+
overwrite: options[:overwrite],
|
|
49
|
+
storage: storage
|
|
21
50
|
)
|
|
22
51
|
tiler.slice! do |path|
|
|
23
52
|
puts path
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module DZT
|
|
2
|
+
class FileStorage
|
|
3
|
+
#
|
|
4
|
+
# @param destination: Full directory in which to output tiles, defaults to 'tiles' in the current dir.
|
|
5
|
+
#
|
|
6
|
+
def initialize(options = {})
|
|
7
|
+
@store_path = options[:destination] || File.join(Dir.pwd, 'tiles')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def exists?
|
|
11
|
+
File.directory?(@store_path) && ! Dir["@{@store_path}/*"].empty?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def storage_location(level)
|
|
15
|
+
File.join(@store_path, level.to_s)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def mkdir(path)
|
|
19
|
+
FileUtils.mkdir_p(path)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def write(file, dest, options = {})
|
|
23
|
+
quality = options[:quality]
|
|
24
|
+
file.write(dest) { @quality = quality if quality }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module DZT
|
|
2
|
+
class S3Storage
|
|
3
|
+
DEFAULT_ACL = 'public-read'
|
|
4
|
+
DEFAULT_KEY = ''
|
|
5
|
+
#
|
|
6
|
+
# @param s3_acl: ACL to use for storing, defaults to 'public-read'.
|
|
7
|
+
# @param s3_bucket: Bucket to store tiles.
|
|
8
|
+
# @param s3_key: Key to prefix stored files.
|
|
9
|
+
# @param aws_id: AWS Id.
|
|
10
|
+
# @param aws_secret: AWS Secret.
|
|
11
|
+
#
|
|
12
|
+
def initialize(options = {})
|
|
13
|
+
@s3_acl = options[:s3_acl] || DEFAULT_ACL
|
|
14
|
+
@s3_bucket = options[:s3_bucket]
|
|
15
|
+
@s3_key = options[:s3_key] || DEFAULT_KEY
|
|
16
|
+
@s3_id = options[:aws_id]
|
|
17
|
+
@s3_secret = options[:aws_secret]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def s3
|
|
21
|
+
@s3 ||= Fog::Storage.new(
|
|
22
|
+
provider: 'AWS',
|
|
23
|
+
aws_access_key_id: @s3_id,
|
|
24
|
+
aws_secret_access_key: @s3_secret
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Currently does not supporting checking S3 fo overwritten files
|
|
29
|
+
def exists?
|
|
30
|
+
false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def storage_location(level)
|
|
34
|
+
"#{@s3_key}/#{level.to_s}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# no-op
|
|
38
|
+
def mkdir(path)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def write(file, dest, options = {})
|
|
42
|
+
quality = options[:quality]
|
|
43
|
+
s3.put_object(@s3_bucket, dest, file.to_blob { @quality = quality if quality },
|
|
44
|
+
'Content-Type' => file.mime_type,
|
|
45
|
+
'x-amz-acl' => @s3_acl
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/dzt/tiler.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# Deep Zoom module for generating Deep Zoom (DZI) tiles from a source image
|
|
2
|
+
require_relative 'file_storage'
|
|
3
|
+
require_relative 's3_storage'
|
|
2
4
|
module DZT
|
|
3
5
|
class Tiler
|
|
4
6
|
# Defaults
|
|
@@ -6,6 +8,7 @@ module DZT
|
|
|
6
8
|
DEFAULT_TILE_OVERLAP = 0
|
|
7
9
|
DEFAULT_QUALITY = 75
|
|
8
10
|
DEFAULT_TILE_FORMAT = "jpg"
|
|
11
|
+
DEFAULT_OVERWRITE_FLAG = false
|
|
9
12
|
|
|
10
13
|
# Generates the DZI-formatted tiles and sets necessary metadata on this object.
|
|
11
14
|
#
|
|
@@ -14,21 +17,24 @@ module DZT
|
|
|
14
17
|
# @param format Format for output tiles (default: "jpg")
|
|
15
18
|
# @param size Size, in pixels, for tile squares (default: 512)
|
|
16
19
|
# @param overlap Size, in pixels, of the overlap between tiles (default: 2)
|
|
17
|
-
# @param overwrite
|
|
18
|
-
# @param
|
|
20
|
+
# @param overwrite Whether or not to overwrite if the destination exists (default: false)
|
|
21
|
+
# @param storage Either an instance of S3Storage or FileStorage
|
|
19
22
|
#
|
|
20
23
|
def initialize(options)
|
|
21
24
|
@tile_source = options[:source]
|
|
22
25
|
raise "Missing options[:source]." unless @tile_source
|
|
26
|
+
|
|
23
27
|
@tile_source = Magick::Image.read(@tile_source)[0] if @tile_source.is_a?(String)
|
|
24
28
|
@tile_size = options[:size] || DEFAULT_TILE_SIZE
|
|
25
29
|
@tile_overlap = options[:overlap] || DEFAULT_TILE_OVERLAP
|
|
26
30
|
@tile_format = options[:format] || DEFAULT_TILE_FORMAT
|
|
31
|
+
|
|
27
32
|
@max_tiled_height = @tile_source.rows
|
|
28
33
|
@max_tiled_width = @tile_source.columns
|
|
34
|
+
|
|
29
35
|
@tile_quality = options[:quality] || DEFAULT_QUALITY
|
|
30
|
-
@overwrite = options[:overwrite] ||
|
|
31
|
-
@
|
|
36
|
+
@overwrite = options[:overwrite] || DEFAULT_OVERWRITE_FLAG
|
|
37
|
+
@storage = options[:storage]
|
|
32
38
|
end
|
|
33
39
|
|
|
34
40
|
##
|
|
@@ -36,10 +42,7 @@ module DZT
|
|
|
36
42
|
# Uses a default tile size of 512 pixels, with a default overlap of 2 pixel.
|
|
37
43
|
##
|
|
38
44
|
def slice!(&block)
|
|
39
|
-
|
|
40
|
-
raise "Output directory #{@destination} already exists!"
|
|
41
|
-
@overwrite ? Rails.logger.warn(msg) : raise(msg)
|
|
42
|
-
end
|
|
45
|
+
raise "Output #{@destination} already exists!" if ! @overwrite && @storage.exists?
|
|
43
46
|
|
|
44
47
|
image = @tile_source.dup
|
|
45
48
|
orig_width, orig_height = image.columns, image.rows
|
|
@@ -48,11 +51,10 @@ module DZT
|
|
|
48
51
|
max_level(orig_width, orig_height).downto(0) do |level|
|
|
49
52
|
width, height = image.columns, image.rows
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
current_level_storage_dir = @storage.storage_location(level)
|
|
55
|
+
@storage.mkdir(current_level_storage_dir)
|
|
54
56
|
if block_given?
|
|
55
|
-
yield
|
|
57
|
+
yield current_level_storage_dir
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
# iterate over columns
|
|
@@ -61,7 +63,7 @@ module DZT
|
|
|
61
63
|
# iterate over rows
|
|
62
64
|
y, row_count = 0, 0
|
|
63
65
|
while y < height
|
|
64
|
-
dest_path = File.join(
|
|
66
|
+
dest_path = File.join(current_level_storage_dir, "#{col_count}_#{row_count}.#{@tile_format}")
|
|
65
67
|
tile_width, tile_height = tile_dimensions(x, y, @tile_size, @tile_overlap)
|
|
66
68
|
|
|
67
69
|
save_cropped_image(image, dest_path, x, y, tile_width, tile_height, @tile_quality)
|
|
@@ -120,7 +122,7 @@ module DZT
|
|
|
120
122
|
# The crop method retains the offset information in the cropped image.
|
|
121
123
|
# To reset the offset data, adding true as the last argument to crop.
|
|
122
124
|
cropped = img.crop(x, y, width, height, true)
|
|
123
|
-
|
|
125
|
+
@storage.write(cropped, dest, quality: quality)
|
|
124
126
|
end
|
|
125
127
|
end
|
|
126
128
|
end
|
data/lib/dzt/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,41 +1,46 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dzt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
prerelease:
|
|
5
6
|
platform: ruby
|
|
6
7
|
authors:
|
|
7
8
|
- Daniel Doubrovkine
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
12
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: gli
|
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
16
18
|
requirements:
|
|
17
|
-
- - '>='
|
|
19
|
+
- - ! '>='
|
|
18
20
|
- !ruby/object:Gem::Version
|
|
19
21
|
version: '0'
|
|
20
22
|
type: :runtime
|
|
21
23
|
prerelease: false
|
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
23
26
|
requirements:
|
|
24
|
-
- - '>='
|
|
27
|
+
- - ! '>='
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
29
|
version: '0'
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
|
28
31
|
name: rmagick
|
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
30
34
|
requirements:
|
|
31
|
-
- - '>='
|
|
35
|
+
- - ! '>='
|
|
32
36
|
- !ruby/object:Gem::Version
|
|
33
37
|
version: '0'
|
|
34
38
|
type: :runtime
|
|
35
39
|
prerelease: false
|
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
37
42
|
requirements:
|
|
38
|
-
- - '>='
|
|
43
|
+
- - ! '>='
|
|
39
44
|
- !ruby/object:Gem::Version
|
|
40
45
|
version: '0'
|
|
41
46
|
description:
|
|
@@ -46,6 +51,8 @@ extensions: []
|
|
|
46
51
|
extra_rdoc_files: []
|
|
47
52
|
files:
|
|
48
53
|
- bin/dzt
|
|
54
|
+
- lib/dzt/file_storage.rb
|
|
55
|
+
- lib/dzt/s3_storage.rb
|
|
49
56
|
- lib/dzt/tiler.rb
|
|
50
57
|
- lib/dzt/version.rb
|
|
51
58
|
- lib/dzt.rb
|
|
@@ -53,28 +60,33 @@ files:
|
|
|
53
60
|
- CONTRIBUTING.md
|
|
54
61
|
- LICENSE.md
|
|
55
62
|
- README.md
|
|
63
|
+
- RELEASING.md
|
|
56
64
|
homepage: http://github.com/dblock/dzt
|
|
57
65
|
licenses:
|
|
58
66
|
- MIT
|
|
59
|
-
metadata: {}
|
|
60
67
|
post_install_message:
|
|
61
68
|
rdoc_options: []
|
|
62
69
|
require_paths:
|
|
63
70
|
- lib
|
|
64
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
65
73
|
requirements:
|
|
66
|
-
- - '>='
|
|
74
|
+
- - ! '>='
|
|
67
75
|
- !ruby/object:Gem::Version
|
|
68
76
|
version: '0'
|
|
77
|
+
segments:
|
|
78
|
+
- 0
|
|
79
|
+
hash: 600770840380266267
|
|
69
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
70
82
|
requirements:
|
|
71
|
-
- - '>='
|
|
83
|
+
- - ! '>='
|
|
72
84
|
- !ruby/object:Gem::Version
|
|
73
85
|
version: 1.3.6
|
|
74
86
|
requirements: []
|
|
75
87
|
rubyforge_project:
|
|
76
|
-
rubygems_version:
|
|
88
|
+
rubygems_version: 1.8.25
|
|
77
89
|
signing_key:
|
|
78
|
-
specification_version:
|
|
90
|
+
specification_version: 3
|
|
79
91
|
summary: Tile images for deep-zoom.
|
|
80
92
|
test_files: []
|
checksums.yaml
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
SHA1:
|
|
3
|
-
metadata.gz: 9ebec393c326ec86c8abdb6f4ccc73c4c74398b8
|
|
4
|
-
data.tar.gz: 647bcbe70edcb2a8718a757cd12f2cbda0eac921
|
|
5
|
-
SHA512:
|
|
6
|
-
metadata.gz: 8735da367c32b01f25ad064685ff460eeaaf874410a99c238932ec3e5a2264df35a6eff169f3057ec3bb1cfd7650a6929084faa68d3391bd111602c998ac6b9d
|
|
7
|
-
data.tar.gz: 65cdf93cb7fb7bd6a8926f9410456fbb38def9193ffb7832a7eeb1167fd61281dadf1873f0122b27c60c9cc2db121fc55ae99674f6e76e49cf090f44ec9254c3
|