Skip to content

Commit 282e722

Browse files
emmmilesverrirs
authored andcommitted
passing generic flags to cwebp
1 parent 728711e commit 282e722

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

lib/jekyll-webp/defaults.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ module Webp
66
DEFAULT = {
77
'enabled' => false,
88

9-
# The quality of the webp conversion 0 to 100 (where 100 is least lossy)
10-
'quality' => 75,
9+
# The flags to pass to the webp binary. For a list of valid parameters check here:
10+
# https://developers.google.com/speed/webp/docs/cwebp#options
11+
'flags' => "-q 75",
1112

1213
# List of directories containing images to optimize, Nested directories will not be checked
1314
'img_dir' => ["/img"],
@@ -35,4 +36,4 @@ module Webp
3536
}
3637

3738
end # module Webp
38-
end # module Jekyll
39+
end # module Jekyll

lib/jekyll-webp/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Jekyll
22
module Webp
3-
VERSION = "0.1.1"
3+
VERSION = "1.0.0"
44
# When modifying remember to issue a new tag command in git before committing, then push the new tag
55
# git tag -a v0.1.0 -m "Gem v0.1.0"
66
# git push origin --tags
77
end #module Webp
8-
end #module Jekyll
8+
end #module Jekyll

lib/jekyll-webp/webpExec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class WebpExec
99
# Runs the WebP executable for the given input parameters
1010
# the function detects the OS platform and architecture automatically
1111
#
12-
def self.run(quality, input_file, output_file)
12+
def self.run(flags, input_file, output_file)
1313

1414
# What is the path to the execs inside the gem? perhaps just bin/?
1515
bin_path = "bin/"
@@ -27,7 +27,7 @@ def self.run(quality, input_file, output_file)
2727
full_path = File.join(gem_root, bin_path, exe_name)
2828

2929
# Construct the full program call
30-
cmd = "\"#{full_path}\" -quiet -mt -q #{quality.to_s} \"#{input_file}\" -o \"#{output_file}\""
30+
cmd = "\"#{full_path}\" -quiet -mt \"#{flags}\" \"#{input_file}\" -o \"#{output_file}\""
3131

3232
# Execute the command
3333
stdin, stdout, stderr = Open3.popen3(cmd)
@@ -88,4 +88,4 @@ def OS.x64?
8888
return 1.size == 8
8989
end
9090
end #module OS
91-
end #module Jekyll
91+
end #module Jekyll

lib/jekyll-webp/webpGenerator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def generate(site)
8282
end
8383

8484
# Generate the file
85-
WebpExec.run(@config['quality'], imgfile, outfile_fullpath_webp)
85+
WebpExec.run(@config['flags'], imgfile, outfile_fullpath_webp)
8686

8787
# Keep the webp file from being cleaned by Jekyll
8888
site.static_files << WebpFile.new(site, site.dest, imgdir, outfile_fullpath_webp)

0 commit comments

Comments
 (0)