jekyll-image-resizer 0.7.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/jekyll-image-resizer.gemspec +25 -0
- data/lib/jekyll-image-resizer/command.rb +73 -0
- data/lib/jekyll-image-resizer/processor.rb +10 -0
- data/lib/jekyll-image-resizer/resizer.rb +132 -0
- data/lib/jekyll-image-resizer/thumbnail.rb +27 -0
- data/lib/jekyll-image-resizer/version.rb +5 -0
- data/lib/jekyll-image-resizer/water_mark.rb +17 -0
- data/lib/jekyll-image-resizer.rb +8 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51b6ca8eb5790b1370a88c1ab7a6bca25992723acf11e369a6c784a3c1d03304
|
4
|
+
data.tar.gz: 9dd59dac140750998c208af6ea3670d3c0ee17b2a16ef0bad4a01043769eba96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5cbdba0c31a9f4ae24763b1a59ecd730b2b71ab4bd37d7eccd173049baabaa1164a2dfff47921d2e907fb88b902de17667206a8c24d910204f381b48643ce8c2
|
7
|
+
data.tar.gz: afa5f0f982bd19b44a8de7ece1f38619a4b29e37041a270697a1fe7871600b76cfdc3eb0ec8327935b0a28afca5a8ea72cb7cc08cc311442feb13e79078011e8
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Jekyll::Image::Resizer
|
2
|
+
|
3
|
+
Jekyll image resizer plugin. Resize images with simple command.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :jekyll_plugins do
|
11
|
+
gem 'jekyll-image-resizer', git: 'git@github.com:kisakov/jekyll-image-resizer.git'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install jekyll-image-resizer
|
22
|
+
|
23
|
+
And finaly add these to your _config.yml
|
24
|
+
|
25
|
+
```yml
|
26
|
+
image_width: 2048
|
27
|
+
image_small_height: 200
|
28
|
+
image_quality: 90
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
$ jekyll photo 2017-01-15-first-weekend # 1st argument is path or image. Will resize and watermark
|
34
|
+
$ jekyll image 0.jpg # 1st argument is path or image. Will resize and watermark
|
35
|
+
$ jekyll resize 2017-01-15-first-weekend # 1st argument is path or image
|
36
|
+
$ jekyll resize 1.jpg 90 300 # 1st argument is path or image, 2nd is quality 3rd is image small height
|
37
|
+
$ jekyll watermark 2017-01-15-first-weekend # add watermark
|
38
|
+
$ jekyll thumbnail 2.jpg # create thumbnail
|
39
|
+
$ jekyll images 0.jpg # 1st argument is path. Will print image names
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kisakov/jekyll-image-resizer.
|
50
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jekyll/image/resizer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll-image-resizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-image-resizer"
|
8
|
+
spec.version = Jekyll::ImageResizer::VERSION
|
9
|
+
spec.authors = ["kisakov"]
|
10
|
+
spec.email = ["isakov90@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{jekyll image resizer plugin}
|
13
|
+
spec.description = %q{Resize images with simple command}
|
14
|
+
spec.homepage = "http://github.com/kisakov/jekyll-image-resizer"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'jekyll', '>= 3.5', '< 5.0'
|
22
|
+
spec.add_dependency 'mini_magick'
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
25
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module ImageResizer
|
3
|
+
class Command < Jekyll::Command
|
4
|
+
def self.init_with_program(prog)
|
5
|
+
prog.command(:image) do |c|
|
6
|
+
c.alias(:photo)
|
7
|
+
c.syntax "image [options]"
|
8
|
+
c.description 'Resize and watermark images'
|
9
|
+
|
10
|
+
c.action do |args, opts|
|
11
|
+
opts['serving'] = false
|
12
|
+
Jekyll.logger.adjust_verbosity(opts)
|
13
|
+
options = configuration_from_options(opts)
|
14
|
+
|
15
|
+
Processor.process_images(args, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
prog.command(:images) do |c|
|
20
|
+
c.syntax "images [options]"
|
21
|
+
c.description 'Print image names'
|
22
|
+
|
23
|
+
c.action do |args, opts|
|
24
|
+
opts['serving'] = false
|
25
|
+
Jekyll.logger.adjust_verbosity(opts)
|
26
|
+
options = configuration_from_options(opts)
|
27
|
+
|
28
|
+
Resizer.print_images(args, options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
prog.command(:resize) do |c|
|
33
|
+
c.syntax "resize [options]"
|
34
|
+
c.description 'Resize images'
|
35
|
+
|
36
|
+
c.action do |args, opts|
|
37
|
+
opts['serving'] = false
|
38
|
+
Jekyll.logger.adjust_verbosity(opts)
|
39
|
+
options = configuration_from_options(opts)
|
40
|
+
|
41
|
+
Resizer.process_images(args, options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
prog.command(:watermark) do |c|
|
46
|
+
c.syntax "watermark [options]"
|
47
|
+
c.description 'Add watermark to images'
|
48
|
+
|
49
|
+
c.action do |args, opts|
|
50
|
+
opts['serving'] = false
|
51
|
+
Jekyll.logger.adjust_verbosity(opts)
|
52
|
+
options = configuration_from_options(opts)
|
53
|
+
|
54
|
+
WaterMark.process_images(args, options)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
prog.command(:thumbnail) do |c|
|
59
|
+
c.syntax "thumbnail [options]"
|
60
|
+
c.description 'Create thumbnail from image'
|
61
|
+
|
62
|
+
c.action do |args, opts|
|
63
|
+
opts['serving'] = false
|
64
|
+
Jekyll.logger.adjust_verbosity(opts)
|
65
|
+
options = configuration_from_options(opts)
|
66
|
+
|
67
|
+
Thumbnail.process_images(args, options)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module ImageResizer
|
3
|
+
class Resizer
|
4
|
+
attr_accessor :image_width, :image_small_height, :image_quality, :folder, :options, :args, :single_image
|
5
|
+
|
6
|
+
def initialize(args, options)
|
7
|
+
@options = options
|
8
|
+
@args = args
|
9
|
+
post = if args[0] && args[0].include?('.')
|
10
|
+
@single_image = args[0]
|
11
|
+
last_post
|
12
|
+
elsif args[0] && !args[0].include?('.')
|
13
|
+
args[0]
|
14
|
+
else
|
15
|
+
last_post
|
16
|
+
end
|
17
|
+
@image_width = options['image_width']
|
18
|
+
@image_quality = args[1] ? args[1].to_i : options['image_quality']
|
19
|
+
@image_small_height = args[2] ? args[2].to_i : options['image_small_height']
|
20
|
+
@folder = Dir["**/"].select { |dir| dir.include?(post) }.reject { |dir| dir.include?('_site') }.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.process_images(args, options)
|
24
|
+
new(args, options).process
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.print_images(args, options)
|
28
|
+
new(args, options).print_images
|
29
|
+
end
|
30
|
+
|
31
|
+
def process
|
32
|
+
return puts("\nError! Can't find folder with this name.\n") if folder.nil?
|
33
|
+
|
34
|
+
images = if single_image
|
35
|
+
image = "#{folder}#{single_image}"
|
36
|
+
return puts("\nError! There isn't image #{image}\n") unless File.exists?(image)
|
37
|
+
|
38
|
+
[image]
|
39
|
+
else
|
40
|
+
path = "#{folder}*.{jpg,png,gif,jpeg,JPG,JPEG}"
|
41
|
+
return puts("\nError! There are no images inside folder #{folder}\n") if Dir.glob(path).size.zero?
|
42
|
+
|
43
|
+
Dir.glob(path)
|
44
|
+
end
|
45
|
+
|
46
|
+
puts "Folder: #{folder}"
|
47
|
+
puts "Processing images with width: #{image_width}px(small width: #{image_small_height}px) and quality: #{image_quality}% \n\n"
|
48
|
+
puts 'images:'
|
49
|
+
|
50
|
+
images.each do |image|
|
51
|
+
image_name = File.basename(image).downcase
|
52
|
+
image_path = "#{folder}/#{image_name}"
|
53
|
+
|
54
|
+
File.rename(image, image_path)
|
55
|
+
next if image_name.include?('_small.')
|
56
|
+
|
57
|
+
process_image(image_name, image_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "\nAll images in folder \"#{folder}\" were processed."
|
61
|
+
end
|
62
|
+
|
63
|
+
def print_images
|
64
|
+
return puts("\nError! Can't find folder with this name.\n") if folder.nil?
|
65
|
+
|
66
|
+
path = "#{folder}*.{jpg,png,gif,jpeg,JPG,JPEG}"
|
67
|
+
return puts("\nError! There are no images inside folder #{folder}\n") if Dir.glob(path).size.zero?
|
68
|
+
|
69
|
+
puts "Folder: #{folder}"
|
70
|
+
puts 'images:'
|
71
|
+
|
72
|
+
Dir.glob(path).each do |image|
|
73
|
+
image_name = File.basename(image)
|
74
|
+
next if image_name.include?('small.') || image_name.include?('thumbnail')
|
75
|
+
|
76
|
+
puts " - #{image_name}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
def last_post
|
83
|
+
site = Jekyll::Site.new(options)
|
84
|
+
site.reset
|
85
|
+
site.read
|
86
|
+
posts = site.posts.docs
|
87
|
+
|
88
|
+
posts.last.data['slug']
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_image(image_name, image_path)
|
92
|
+
return if image_name.include?('thumbnail')
|
93
|
+
|
94
|
+
puts " - #{image_name}"
|
95
|
+
|
96
|
+
image = resize_image(image_path) do |image, ratio|
|
97
|
+
height = if image.width > image.height
|
98
|
+
image_width / ratio
|
99
|
+
else
|
100
|
+
image_width * ratio
|
101
|
+
end.round
|
102
|
+
|
103
|
+
[image_width, height]
|
104
|
+
end
|
105
|
+
image.write(image_path)
|
106
|
+
|
107
|
+
image = resize_image(image_path) do |image, ratio|
|
108
|
+
width = if image.width > image.height
|
109
|
+
image_small_height * ratio
|
110
|
+
else
|
111
|
+
image_small_height / ratio
|
112
|
+
end.round
|
113
|
+
|
114
|
+
[width, image_small_height]
|
115
|
+
end
|
116
|
+
small_image_name = image_name.gsub!('.', '-small.')
|
117
|
+
image.write("#{folder}/#{small_image_name}")
|
118
|
+
end
|
119
|
+
|
120
|
+
def resize_image(image_path)
|
121
|
+
image = MiniMagick::Image.open(image_path)
|
122
|
+
image.quality(image_quality)
|
123
|
+
ratio = image.width / image.height.to_f
|
124
|
+
|
125
|
+
width, height = yield(image, ratio)
|
126
|
+
|
127
|
+
image.resize "#{width}x#{height}"
|
128
|
+
image
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module ImageResizer
|
3
|
+
class Thumbnail < Resizer
|
4
|
+
attr_accessor :thumbnail_width
|
5
|
+
|
6
|
+
def initialize(args, options)
|
7
|
+
super
|
8
|
+
@thumbnail_width = options['thumbnail_width']
|
9
|
+
end
|
10
|
+
|
11
|
+
def process_image(image_name, image_path)
|
12
|
+
image = resize_image(image_path) do |image, ratio|
|
13
|
+
height = if image.width > image.height
|
14
|
+
thumbnail_width / ratio
|
15
|
+
else
|
16
|
+
thumbnail_width * ratio
|
17
|
+
end.round
|
18
|
+
|
19
|
+
[thumbnail_width, height]
|
20
|
+
end
|
21
|
+
|
22
|
+
thumbnail_image_name = image_name.prepend('thumbnail-')
|
23
|
+
image.write("#{folder}/#{thumbnail_image_name}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module ImageResizer
|
3
|
+
class WaterMark < Resizer
|
4
|
+
def process_image(image_name, image_path)
|
5
|
+
watermark = options['watermark'] || 'assets/images/watermark_karmelalla.png'
|
6
|
+
image = MiniMagick::Image.open(image_path)
|
7
|
+
|
8
|
+
image.combine_options do |c|
|
9
|
+
c.gravity 'SouthEast'
|
10
|
+
c.draw "image Over 0,0 0,0 '#{watermark}'"
|
11
|
+
end
|
12
|
+
|
13
|
+
image.write(image_path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'mini_magick'
|
3
|
+
require 'jekyll-image-resizer/version'
|
4
|
+
require 'jekyll-image-resizer/command'
|
5
|
+
require 'jekyll-image-resizer/resizer'
|
6
|
+
require 'jekyll-image-resizer/water_mark'
|
7
|
+
require 'jekyll-image-resizer/processor'
|
8
|
+
require 'jekyll-image-resizer/thumbnail'
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-image-resizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kisakov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.5'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.5'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mini_magick
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.1'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '13.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '13.0'
|
75
|
+
description: Resize images with simple command
|
76
|
+
email:
|
77
|
+
- isakov90@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".travis.yml"
|
84
|
+
- Gemfile
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- jekyll-image-resizer.gemspec
|
90
|
+
- lib/jekyll-image-resizer.rb
|
91
|
+
- lib/jekyll-image-resizer/command.rb
|
92
|
+
- lib/jekyll-image-resizer/processor.rb
|
93
|
+
- lib/jekyll-image-resizer/resizer.rb
|
94
|
+
- lib/jekyll-image-resizer/thumbnail.rb
|
95
|
+
- lib/jekyll-image-resizer/version.rb
|
96
|
+
- lib/jekyll-image-resizer/water_mark.rb
|
97
|
+
homepage: http://github.com/kisakov/jekyll-image-resizer
|
98
|
+
licenses: []
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.2.32
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: jekyll image resizer plugin
|
119
|
+
test_files: []
|