jekyll-imagemagick 1.1.7

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: 2159dfe9bd500b484cc07f0c7ad1dc795b9a846a
4
+ data.tar.gz: 3855494993f5b50b6e41a051f6a5ea1c7975ef53
5
+ SHA512:
6
+ metadata.gz: e43bbe9fdc39016b4e846758f75be696aa27d2c31764fc764a036306b593fc87a53ec5bc4ba101ca90d6d3cde381d3b0cf73dd5a1d4ae40921e823f97c304a38
7
+ data.tar.gz: d1b53da7e61f493a86665484451b9255cb55f74654bbe4e9a732a2e6cef2f831f12f014ba71b2caa3a49d4fc65651a2c124766b2b453afef9567f4133972a350
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at [jekyll@sverrirs.com](mailto:jekyll@sverrirs.com). All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-imagemagick.gemspec
4
+ gemspec
5
+
6
+ if ENV["JEKYLL_VERSION"]
7
+ gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sverrir Sigmundarson
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+
2
+ # Image Generator for Jekyll
3
+ Image Generator for Jekyll Sites can automatically generate images for all images on your static site and serve them when possible.
4
+
5
+ It uses Imagemagick so it must be installed on the system.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ gem install jekyll-imagemagick
11
+ ```
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push 'lib'
6
+ t.libs.push 'specs'
7
+ t.verbose = true
8
+ t.pattern = "spec/*_spec.rb"
9
+ t.test_files = FileList['spec/*_spec.rb']
10
+ end
11
+
12
+ desc "Run tests"
13
+ task :default => [:test]
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require_relative 'lib/jekyll-imagemagick/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "jekyll-imagemagick"
6
+ spec.version = Jekyll::Imagemagick::VERSION
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.date = DateTime.now.strftime('%Y-%m-%d')
9
+ spec.authors = ["Emilio Del Tessandoro"]
10
+ spec.email = ["emilio.deltessa@gmail.com"]
11
+ spec.homepage = "https://github.com/emmmile/jekyll-imagemagick"
12
+ spec.license = "MIT"
13
+
14
+ spec.summary = %q{Image generator for Jekyll 3 websites}
15
+ spec.description = %q{Image Generator for Jekyll 3 Sites that automatically generate images for all images on your static site and serves them when possible.}
16
+
17
+ spec.files = Dir['CODE_OF_CONDUCT.md', 'README.md', 'LICENSE', 'Rakefile', '*.gemspec', 'Gemfile', 'lib/**/*', 'spec/**/*', 'bin/**/*']
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^spec/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "jekyll", "~> 3.0"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake", "~> 1.5"
25
+ spec.add_development_dependency "minitest", '~> 5.4', '>= 5.4.3'
26
+ spec.add_runtime_dependency "fastimage", '~> 2.1'
27
+ end
@@ -0,0 +1,9 @@
1
+ require "jekyll-imagemagick/version"
2
+ require "jekyll-imagemagick/defaults"
3
+ require "jekyll-imagemagick/imageConvert"
4
+ require "jekyll-imagemagick/imageGenerator"
5
+
6
+ module Jekyll
7
+ module Imagemagick
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module Jekyll
2
+ module Imagemagick
3
+ # The default configuration for the Imagemagick generator
4
+ # The values here represent the defaults if nothing is set
5
+ # TODO
6
+ DEFAULT = {
7
+ 'enabled' => false,
8
+
9
+ # The flags to pass to the convert binary.
10
+ 'flags' => "-q 75",
11
+
12
+ # List of directories containing images to optimize, Nested directories will not be checked
13
+ 'input_directories' => ["/img"],
14
+
15
+ # List of resolutions to generate, 0 means full size otherwise is the long edge
16
+ 'edges' => [0, 1024, 512],
17
+
18
+ # Flags for resizing
19
+ 'resize_flags' => '-filter Lanczos',
20
+
21
+ # add ".gif" to the format list to generate images for animated gifs as well
22
+ 'input_formats' => [".png", ".tiff"],
23
+
24
+ # Local path to the WebP utilities to use (relative or absolute)
25
+ 'webp_path' => nil,
26
+
27
+ # List of files or directories to exclude
28
+ 'exclude' => [],
29
+
30
+ # List of files or directories to explicitly include
31
+ # e.g. single files outside of the main image directories
32
+ 'include' => []
33
+ }
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ require 'open3'
2
+ require 'fastimage'
3
+
4
+ module Jekyll
5
+ module Imagemagick
6
+ class ImageConvert
7
+ # Executes a command and wait for the output
8
+ def self.run_cmd(cmd)
9
+ exit_code = 0
10
+ error = ""
11
+ output = ""
12
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
13
+ stdin.close # we don't pass any input to the process
14
+ output = stdout.gets
15
+ error = stderr.gets
16
+ exit_code = wait_thr.value
17
+ end
18
+
19
+ if exit_code != 0
20
+ Jekyll.logger.error("Imagemagick:", "Command returned #{exit_code} with error #{error}")
21
+ end
22
+
23
+ # Return any captured return value
24
+ return [output, error]
25
+ end
26
+
27
+
28
+ def self.run(input_file, output_file, flags, long_edge, resize_flags)
29
+ width, height = FastImage.size(input_file)
30
+
31
+ Jekyll.logger.info("Imagemagick:", "Generating image \"#{output_file}\"")
32
+ cmd = "convert \"#{input_file}\" #{flags} "
33
+ if long_edge != 0
34
+ cmd += "-resize \"#{long_edge.to_s}>\" #{resize_flags} "
35
+ end
36
+ cmd += "\"#{output_file}\""
37
+ Jekyll.logger.debug("Imagemagick:", "Running command \"#{cmd}\"")
38
+ run_cmd(cmd)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,127 @@
1
+ require 'jekyll/document'
2
+ require 'fileutils'
3
+
4
+ module Jekyll
5
+ module Imagemagick
6
+ # A static file to hold the generated webp image after generation
7
+ # so that Jekyll will copy it into the site output directory
8
+ class ImageFile < StaticFile
9
+ def write(dest)
10
+ true # Recover from strange exception when starting server without --auto
11
+ end
12
+ end
13
+
14
+ class ImageGenerator < Generator
15
+ # This generator is safe from arbitrary code execution.
16
+ safe true
17
+
18
+ # This generator should be passive with regard to its execution
19
+ priority :lowest
20
+
21
+ # Return all the files to convert
22
+ def get_files_to_transform(site, directories, input_formats)
23
+ files = []
24
+
25
+ for directory in directories
26
+ directory_full_path = File.join(site.source, directory)
27
+ Jekyll.logger.info("Imagemagick:", "Searching files in #{directory_full_path}")
28
+
29
+ for file_full_path in Dir[directory_full_path + "**/*.*"]
30
+ # If the file_full_path is not one of the supported formats, exit early
31
+ extension = File.extname(file_full_path).downcase
32
+ next if !input_formats.include? extension
33
+
34
+ files.push(file_full_path)
35
+ end
36
+ end
37
+
38
+ return files
39
+ end
40
+
41
+ # Returns a list (input, output, edge)
42
+ def compute_file_transformations(site, input_files_full_path, formats, edges)
43
+ output = []
44
+
45
+ if formats.length == 0
46
+ Jekyll.logger.error("Imagemagick:", "No output formats found")
47
+ return output
48
+ end
49
+
50
+ for input_file_full_path in input_files_full_path
51
+ formats.each do |format_extension, flags|
52
+ for edge in edges
53
+ extension = File.extname(input_file_full_path)
54
+ prefix = File.dirname(input_file_full_path.sub(site.source, ""))
55
+ suffix = ""
56
+ if edge != 0
57
+ suffix = "-" + edge.to_s
58
+ end
59
+ filename = File.basename(input_file_full_path, extension) + suffix + "." + format_extension.to_s
60
+ output_file_full_path = File.join(site.dest + prefix, filename)
61
+ output.push([input_file_full_path, output_file_full_path, edge])
62
+ end
63
+ end
64
+ end
65
+
66
+ return output
67
+ end
68
+
69
+ def generate_output_paths(site, tuples)
70
+ for tuple in tuples
71
+ input, output, edge = tuple
72
+ directory = File.dirname(output)
73
+ FileUtils::mkdir_p(directory)
74
+ end
75
+ end
76
+
77
+ def generate_files(site, tuples, formats)
78
+ generated_files = 0
79
+
80
+ for tuple in tuples
81
+ input_file_full_path, output_file_full_path, edge = tuple
82
+ # Check if the file already has a webp alternative?
83
+ # If we're force rebuilding all webp files then ignore the check
84
+ # also check the modified time on the files to ensure that the webp file
85
+ # is newer than the source file, if not then regenerate
86
+ if !File.file?(output_file_full_path) ||
87
+ (File.mtime(output_file_full_path) <= File.mtime(input_file_full_path))
88
+ # Generate the file
89
+ extension = File.extname(output_file_full_path).sub('.', '')
90
+ ImageConvert.run(input_file_full_path, output_file_full_path, formats[extension], edge, @config['resize_flags'])
91
+ generated_files += 1
92
+ end
93
+ if File.file?(output_file_full_path)
94
+ # Keep the webp file from being cleaned by Jekyll
95
+ prefix = File.dirname(input_file_full_path.sub(site.source, ""))
96
+ Jekyll.logger.info("Imagemagick:", "Adding static file #{site.dest + prefix + "/" + File.basename(output_file_full_path)}")
97
+ site.static_files << ImageFile.new(site, site.dest, prefix, File.basename(output_file_full_path))
98
+ end
99
+ end
100
+
101
+ return generated_files
102
+ end
103
+
104
+ # Do the transformations
105
+ def generate(site)
106
+ # Retrieve and merge the configuration from the site yml file
107
+ @config = DEFAULT.merge(site.config['imagemagick'] || {})
108
+
109
+ # If disabled then simply quit
110
+ if !@config['enabled']
111
+ Jekyll.logger.info("Imagemagick:", "Disabled in site.config.")
112
+ return
113
+ end
114
+
115
+ # If the site destination directory has not yet been created then create it now. Otherwise, we cannot write our file there.
116
+ Dir::mkdir(site.dest) if !File.directory? site.dest
117
+
118
+ files = get_files_to_transform(site, @config['input_directories'], @config['input_formats'])
119
+ tuples = compute_file_transformations(site, files, @config['output_formats'], @config['edges'])
120
+ generate_output_paths(site, tuples)
121
+ generated_files = generate_files(site, tuples, @config['output_formats'])
122
+
123
+ Jekyll.logger.info("Imagemagick:", "Generated #{generated_files} file(s)")
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,8 @@
1
+ module Jekyll
2
+ module Imagemagick
3
+ VERSION = "1.1.7"
4
+ # When modifying remember to issue a new tag command in git before committing, then push the new tag
5
+ # git tag -a v0.1.0 -m "Gem v0.1.0"
6
+ # git push origin --tags
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-imagemagick
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Emilio Del Tessandoro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-02 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.4'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 5.4.3
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '5.4'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 5.4.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: fastimage
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.1'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.1'
89
+ description: Image Generator for Jekyll 3 Sites that automatically generate images
90
+ for all images on your static site and serves them when possible.
91
+ email:
92
+ - emilio.deltessa@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - LICENSE
100
+ - README.md
101
+ - Rakefile
102
+ - jekyll-imagemagick.gemspec
103
+ - lib/jekyll-imagemagick.rb
104
+ - lib/jekyll-imagemagick/defaults.rb
105
+ - lib/jekyll-imagemagick/imageConvert.rb
106
+ - lib/jekyll-imagemagick/imageGenerator.rb
107
+ - lib/jekyll-imagemagick/version.rb
108
+ homepage: https://github.com/emmmile/jekyll-imagemagick
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.14
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Image generator for Jekyll 3 websites
132
+ test_files: []