make_gallery 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73a420c6d379b22fae3b4320a397324c1a7e9cba
4
+ data.tar.gz: 3bf62a77bddd091ca3d93dfd2baadffd2505ec99
5
+ SHA512:
6
+ metadata.gz: 9b9d88b28024fc62202cd4e178120734999d2ea83853e6fdd5a2faa88f831b0dc2655a09fdbd8feb03ef4e03eb03b8c4f717178ec38f821c1f82f208009ae3bc
7
+ data.tar.gz: b976924eb22534315f2ba0e0ec807f3255a84d4d575fa6c5cb9ff01457ecb51b5f32759f19c7c82abd5cb0b3f307474a2fc2f15f60f3b4b7c3cb30af8d9bcaa7
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ spec/test_output/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # ChangeLog
2
+
3
+ # Next Release: 0.1.0
4
+
5
+ * First pre-release
@@ -0,0 +1,32 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect
4
+ all people who contribute through reporting issues, posting feature
5
+ requests, updating documentation, submitting pull requests or patches,
6
+ and other activities.
7
+
8
+ We are committed to making participation in this project a
9
+ harassment-free experience for everyone, regardless of level of
10
+ experience, gender, gender identity and expression, sexual
11
+ orientation, disability, personal appearance, body size, race, age, or
12
+ religion.
13
+
14
+ Examples of unacceptable behavior by participants include the use of
15
+ sexual language or imagery, derogatory comments or personal attacks,
16
+ trolling, public or private harassment, insults, or other
17
+ unprofessional conduct.
18
+
19
+ Project maintainers have the right and responsibility to remove, edit,
20
+ or reject comments, commits, code, wiki edits, issues, and other
21
+ contributions that are not aligned to this Code of Conduct. Project
22
+ maintainers who do not follow the Code of Conduct may be removed from
23
+ the project team.
24
+
25
+ Instances of abusive, harassing, or otherwise unacceptable behavior
26
+ may be reported by opening an issue or contacting one or more of the
27
+ project maintainers.
28
+
29
+ This Code of Conduct is adapted from the
30
+ [Contributor Covenant](http:contributor-covenant.org), version 1.0.0,
31
+ available at
32
+ [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,17 @@
1
+ # Guidelines for Contributing
2
+
3
+ Read the [Code of Conduct](CODE_OF_CONDUCT.md) and agree to follow
4
+ it.
5
+
6
+ Use the GitHub [Issues]() tool to report any issues, ask questions,
7
+ get help, etc.
8
+
9
+ Create extra documentation in the project [Wiki]() on GitHub.
10
+
11
+ Write missing tests.
12
+
13
+ Add great new features.
14
+
15
+ Tell me how you use it.
16
+
17
+ Share it.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in make_gallery.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tamara Temple
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # MakeGallery
2
+
3
+ I like to show several pictures in some of my blog posts as a gallery
4
+ of sorts, with square thumbnails that link to the web-sized images.
5
+
6
+ I found a nifty one-line bash command that uses ImageMagick to
7
+ automate part of this process:
8
+
9
+ ``` bash
10
+ #!/bin/bash
11
+
12
+ set -xv
13
+
14
+ : ${THUMBSIZE:=200}
15
+ : ${THUMBNAIL:=${THUMBSIZE}x${THUMBSIZE}}
16
+
17
+ mkdir -p thumbs
18
+ mogrify -format gif -path thumbs -thumbnail ${THUMBNAIL}^ -gravity center -extent ${THUMBNAIL} *.jpg
19
+ ```
20
+
21
+ which creates small-ish .gif thumbnails in a `thumbs/` subdirectory.
22
+
23
+ In addition, I want to create web-scale .jpgs in a `web/` subdirectory
24
+ (mid-quality 1024 pixels wide).
25
+
26
+ ## Installation
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install make_gallery
31
+
32
+ ## Usage
33
+
34
+ $ make_gallery (thumbs | web) [--source DIR] [--target DIR] [--size SIZE] [--format FORMAT] [--force] [--verbose] [--debug]
35
+
36
+ * **thumbs:** create (square) thumbnails
37
+ * **web:** create web-sized images (maintains aspect ratio)
38
+ * *source:* the directory to take starting images from (default is current directory)
39
+ * *target:* the directory to write to (default is `./thumbs/` or `./web/`)
40
+ * *size:* horizontal size for web images, side size for thumbs
41
+ * *format:* JPG for web images, GIF for thumbs
42
+ * *force:* overwrite (default is abort if directory already exists)
43
+ * *verbose:* be chatty
44
+ * *debug:* be SUPER chatty about a lot of things
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install
49
+ dependencies. Then, run `bin/console` for an interactive prompt that
50
+ will allow you to experiment. Run `bundle exec make_gallery` to use
51
+ the code located in this directory, ignoring other installed copies of
52
+ this gem.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake
55
+ install`. To release a new version, update the version number in
56
+ `version.rb`, and then run `bundle exec rake release` to create a git
57
+ tag for the version, push git commits and tags, and push the `.gem`
58
+ file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Review the [Guidelines](CONTRIBUTING.md) for any information on how to contribute to this tool.
63
+
64
+ Make sure to also read the [Code of Conduct](CODE_OF_CONDUCT.md) if you wish to contribute.
65
+
66
+ 1. Fork it ( https://github.com/tamouse/make_gallery/fork )
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create a new Pull Request
71
+
72
+ *"fork in, branch it, commit it, push it." -- daft punking our way through open source!*
73
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "make_gallery"
5
+ require "pry"
6
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/make_gallery ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "make_gallery"
4
+
5
+ MakeGallery::Thor.start
@@ -0,0 +1,142 @@
1
+ require 'fattr'
2
+ require 'highline'
3
+
4
+ module MakeGallery
5
+ class Command
6
+
7
+ OUTLOG = HighLine.new($stdin, $stdout)
8
+ ERRLOG = HighLine.new($stdin, $stderr)
9
+
10
+ FATTRS = %w[action source target size format quality force verbose debug dry_run mogrify_path]
11
+
12
+ fattrs *FATTRS
13
+
14
+ def fattrs
15
+ self.class.fattrs
16
+ end
17
+
18
+
19
+ def initialize(action, options)
20
+ action(action)
21
+
22
+ options.each do |k, v|
23
+ public_send k, v
24
+ end
25
+
26
+ if debug
27
+ fattrs.each do |attr|
28
+ a = ERRLOG.color(attr, :cyan, :on_black)
29
+ b = ERRLOG.color(public_send(attr).inspect, :white, :on_black)
30
+ ERRLOG.say("DEBUG: #{a}: #{b}")
31
+ end
32
+ end
33
+
34
+ fatal_say("#{target} exists. Use --force to overwrite") if File.exists?(target) && ! force
35
+ end
36
+
37
+ def to_h
38
+ fattrs.inject({}) {|hash, attr| hash.update attr => public_send(attr) }
39
+ end
40
+
41
+ def process_images
42
+ say("Creating #{action} images in #{source} to #{target}\n", :green)
43
+
44
+ FileUtils.mkdir_p(target) unless dry_run
45
+
46
+ cmd = build_command.join(" ")
47
+ say("\nRunning: #{cmd}", :green)
48
+
49
+ # skip the rest if it's a dry run
50
+ unless dry_run
51
+ o, e, s = Open3.capture3(cmd)
52
+ fatal e unless s.success?
53
+ say("\nOutput:\n", :green)
54
+ say(o, :cyan)
55
+ say(e, :cyan)
56
+ say("\n")
57
+ end
58
+
59
+ say("\nCompleted\n", :green)
60
+ end
61
+
62
+ def build_command
63
+ mogrify = locate_mogrify
64
+ cmd_opts = set_mogrify_options
65
+ source_images = select_source_images
66
+ [mogrify, cmd_opts, source_images].flatten.tap do |t|
67
+ debug_say("Command: #{t.inspect}")
68
+ end
69
+ end
70
+
71
+
72
+ def locate_mogrify
73
+ if mogrify_path
74
+ fatal_say("Path given for mogrify command is wrong") unless File.exist?(mogrify_path)
75
+ mogrify = mogrify_path
76
+ else
77
+ mogrify = %x(which mogrify).chomp
78
+ fatal_say("Cannot find mogrify command. Use --mogrify_path option instead") unless File.exist?(mogrify)
79
+ end
80
+ debug_say("mogrify command: #{mogrify.inspect}")
81
+ mogrify
82
+ end
83
+
84
+ def set_mogrify_options
85
+ cmd_opts = []
86
+ cmd_opts << "-verbose" if verbose
87
+ cmd_opts << "-format #{format}"
88
+ cmd_opts << "-path #{target}"
89
+ cmd_opts << "-quality #{quality}"
90
+
91
+ if action == :thumbs
92
+ geometry = [size, size].join("x")
93
+ cmd_opts << "-thumbnail #{geometry}^"
94
+ cmd_opts << "-gravity center"
95
+ cmd_opts << "-extent #{geometry}"
96
+ elsif action == :web
97
+ cmd_opts << "-resize #{size}"
98
+ end
99
+
100
+ debug_say "command opts: #{cmd_opts.inspect}"
101
+ cmd_opts
102
+ end
103
+
104
+ def select_source_images
105
+ debug_say "source: #{source}"
106
+ debug_say "source files: #{Dir[File.join(source,'*')]}"
107
+ source_images = Dir[File.join(source,'*')].grep(/jpe?g|png|gif/i)
108
+ debug_say "source images: #{source_images.inspect}"
109
+ fatal_say("No images found in #{source}!") if source_images.empty?
110
+ source_images
111
+ end
112
+
113
+ def say(m, *colors)
114
+ if colors.empty?
115
+ colors = [:red, :on_black, :bold]
116
+ end
117
+
118
+ m = OUTLOG.color(m, *colors)
119
+ OUTLOG.say(m) if verbose
120
+ end
121
+
122
+ def fatal_say(m, *colors)
123
+ if colors.empty?
124
+ colors = [:red, :on_black, :bold]
125
+ end
126
+
127
+ m = ERRLOG.color(m, *colors)
128
+ ERRLOG.say("FATAL: #{m}")
129
+
130
+ raise MakeGallery::Exception.new(m)
131
+ end
132
+
133
+ def debug_say(m, *colors)
134
+ if colors.empty?
135
+ colors = [:yellow, :on_black, :bold]
136
+ end
137
+
138
+ m = ERRLOG.color(m, *colors)
139
+ ERRLOG.say("DEBUG: #{m}") if debug
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,3 @@
1
+ module MakeGallery
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,66 @@
1
+ require "thor"
2
+ require "fileutils"
3
+ require "open3"
4
+ require "make_gallery/command"
5
+
6
+ module MakeGallery
7
+ class Exception < RuntimeError; end
8
+
9
+ class Thor < Thor
10
+
11
+ include Thor::Actions
12
+
13
+ class_option(:force, type: :boolean, aliases: %w[-F], default: false,
14
+ desc: "overwrite if directory or files exist")
15
+ class_option(:verbose, type: :boolean, aliases: %w[-V], default: false,
16
+ desc: "be chatty")
17
+ class_option(:debug, type: :boolean, aliases: %w[-D], default: false,
18
+ desc: "be even *more* chatty")
19
+ class_option(:dry_run, type: :boolean, aliases: %w[-n], default: false,
20
+ desc: "Dry run, just show would happen, but do not do it")
21
+ class_option(:mogrify_path, type: :string,
22
+ desc: "path to mogrify command if make_gallery cannot find it")
23
+
24
+
25
+ desc "thumbs", "Make small, square thumbnails of images in the source directory, saving them in the target directory."
26
+ method_option(:source, type: :string, aliases: %w[-s], default: ".",
27
+ desc: "source directory for images",
28
+ banner: "DIR")
29
+ method_option(:target, type: :string, aliases: %w[-t], default: "./thumbs/",
30
+ desc: "destination directory for thumbnails",
31
+ banner: "DIR")
32
+ method_option(:size, type: :numeric, aliases: %w[-w], default: 200,
33
+ desc: "height and width in pixels")
34
+ method_option(:format, type: :string, aliases: %w[-f], default: "gif",
35
+ desc: "format of thumbnail")
36
+ method_option(:quality, type: :numeric, aliases: %w[-q], default: 60,
37
+ desc: "quality of image")
38
+ def thumbs
39
+ MakeGallery::Command.new(:thumbs, options).process_images
40
+ rescue MakeGallery::Exception => e
41
+ return e.to_s
42
+ end
43
+
44
+ desc "web", "Make web-sized images of the images in the source directory, saving them in the target directory. The new images retain the same aspect ratio as the source images."
45
+ method_option(:source, type: :string, aliases: %w[-s], default: ".",
46
+ desc: "source directory for images",
47
+ banner: "DIR")
48
+ method_option(:target, type: :string, aliases: %w[-t], default: "./web/",
49
+ desc: "destination directory for thumbnails",
50
+ banner: "DIR")
51
+ method_option(:size, type: :numeric, aliases: %w[-w], default: 1024,
52
+ desc: "horizontal width in pixels")
53
+ method_option(:format, type: :string, aliases: %w[-f], default: "jpg",
54
+ desc: "format of thumbnail")
55
+ method_option(:quality, type: :numeric, aliases: %w[-q], default: 60,
56
+ desc: "quality of image")
57
+ def web
58
+ MakeGallery::Command.new(:web, options).process_images
59
+ rescue MakeGallery::Exception => e
60
+ return e.to_s
61
+ end
62
+
63
+ private
64
+
65
+ end
66
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "make_gallery/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "make_gallery"
8
+ spec.version = MakeGallery::VERSION
9
+ spec.authors = ["Tamara Temple"]
10
+ spec.email = ["tamouse@gmail.com"]
11
+ spec.summary = %q{Create a set of images for a blog gallery.}
12
+ spec.homepage = "https://github.com/tamouse"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "thor"
21
+ spec.add_dependency "fattr"
22
+ spec.add_dependency "highline"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry-byebug"
28
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: make_gallery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Tamara Temple
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fattr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - tamouse@gmail.com
114
+ executables:
115
+ - make_gallery
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - CHANGELOG.md
123
+ - CODE_OF_CONDUCT.md
124
+ - CONTRIBUTING.md
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - exe/make_gallery
132
+ - lib/make_gallery.rb
133
+ - lib/make_gallery/command.rb
134
+ - lib/make_gallery/version.rb
135
+ - make_gallery.gemspec
136
+ homepage: https://github.com/tamouse
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.5
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Create a set of images for a blog gallery.
160
+ test_files: []