webp-ffi 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c6477ba5c12959272c5f876298ebf8fe7ca91da5
4
- data.tar.gz: b6cdddd80a1de784a3e649143e98d8a08d70303b
2
+ SHA256:
3
+ metadata.gz: 976dae5457f3f3f651095f92ac882a9dc9f8dbe5bb52a99cf07d834c2ef020b3
4
+ data.tar.gz: 914c57979aa313a2f999b9031cecd60439fa6a73d4e4e81c0b8c61263c3d1539
5
5
  SHA512:
6
- metadata.gz: e656666a00108b7b524b366a43803228c6c99a8d8995b7d2ed69eaa20e3a3c128123d9d0c917208b64ed632a2f9ffe7f92cd4ab32105afda352b51e67a7ca5eb
7
- data.tar.gz: c70b6c901fa02e7ad934394d9bc250b01ac357cf5f60822db083da38ccb496890d2ce6381824c2d3193a0da57579649b798bbe997f0dea72366697b1bf7b0999
6
+ metadata.gz: 3bfeb83ba2b884165cabba2dba3409eb6ea1c6f9def8190f2a5f3ac86c2393b91faa432ae1258b36410a02921b2a1273d5bd4e50c04ca5b0e4e6c19f6a5b9e8a
7
+ data.tar.gz: fd9fc4f3ded81c06a54c9c606fa63c6d51ef7c1943be9a59ade65124d5589ed4216e20d823a74fcc80a65be09c61a9f99955b2cbd3817a5e7d52d732df1e7879
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.5.3
data/.travis.yml CHANGED
@@ -8,9 +8,13 @@ before_install:
8
8
 
9
9
 
10
10
  rvm:
11
- - 1.9.3
12
- - 2.0.0
13
- - 2.1.5
11
+ - 2.0
12
+ - 2.1
13
+ - 2.2
14
+ - 2.3.3
15
+ - 2.4.1
16
+ - 2.5.3
17
+ - 2.6.1
14
18
  - jruby-19mode
15
19
  - rbx-19mode
16
20
  - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## v0.2.6
2
+
3
+ * Tested on webp 1.0.2
4
+ * Added near_lossless option
5
+
6
+ ## v0.2.5
7
+
8
+ * Fix build for Travis CI docker containers
9
+
1
10
  ## v0.2.4
2
11
 
3
12
  * DRY C code and split into files each read/write formats
data/README.md CHANGED
@@ -19,6 +19,10 @@ For Ubuntu, Debian:
19
19
 
20
20
  sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libwebp-dev
21
21
 
22
+ For Fedora, CentOS:
23
+
24
+ sudo dnf install libjpeg-devel libpng-devel libtiff-devel libwebp-devel
25
+
22
26
  For Mac OS:
23
27
 
24
28
  brew install libjpg libpng libtiff webp
@@ -85,6 +89,7 @@ Encode png, jpg or tiff image to webp with options:
85
89
  Possible encode options:
86
90
 
87
91
  * **lossless** (int) - Lossless encoding (0=lossy(default), 1=lossless)
92
+ * **near_lossless** (int) - Use near-lossless image preprocessing (0=maximum preprocessing, 100=no preprocessing(default))
88
93
  * **quality** (float) - between 0 (smallest file) and 100 (biggest)
89
94
  * **method** (int) - quality/speed trade-off (0=fast, 6=slower-better)
90
95
  * **target\_size** (int) - if non-zero, set the desired target size in bytes. Takes precedence over the 'compression' parameter
@@ -142,6 +147,47 @@ Possible decode options:
142
147
  * **crop\_x** (int), **crop\_y** (int), **crop\_w** (int), **crop\_h** (int) - crop picture with the given rectangle
143
148
  * **resize\_w** (int), **resize\_h** (int) - resize picture (after any cropping)
144
149
 
150
+ ## Rails assets pipeline integration
151
+
152
+ For integration with Rails 3+ you can use very simple rake task:
153
+
154
+ ```ruby
155
+ # Place this code in lib/tasks/assets.rake
156
+ require 'webp-ffi'
157
+
158
+ namespace :assets do
159
+ desc "Create .webp versions of assets"
160
+ task :webp => :environment do
161
+ image_types = /\.(?:png|jpe?g)$/
162
+
163
+ public_assets = File.join(
164
+ Rails.root,
165
+ "public",
166
+ Rails.application.config.assets.prefix)
167
+
168
+ Dir["#{public_assets}/**/*"].each do |filename|
169
+ next unless filename =~ image_types
170
+
171
+ mtime = File.mtime(filename)
172
+ webp_file = "#{filename}.webp"
173
+ next if File.exist?(webp_file) && File.mtime(webp_file) >= mtime
174
+ begin
175
+ WebP.encode(filename, webp_file)
176
+ File.utime(mtime, mtime, webp_file)
177
+ puts "Webp converted image #{webp_file}"
178
+ rescue => e
179
+ puts "Webp convertion error of image #{webp_file}. Error info: #{e.message}"
180
+ end
181
+ end
182
+ end
183
+
184
+ # Hook into existing assets:precompile task
185
+ Rake::Task["assets:precompile"].enhance do
186
+ Rake::Task["assets:webp"].invoke
187
+ end
188
+ end
189
+ ```
190
+
145
191
  ## Contributing
146
192
 
147
193
  1. Fork it
@@ -64,6 +64,10 @@ int webp_encode(const char *in_file, const char *out_file, const FfiWebpEncodeCo
64
64
  if (encode_config->lossless == 0 || encode_config->lossless == 1){
65
65
  config.lossless = encode_config->lossless;
66
66
  }
67
+ if (encode_config->near_lossless >= 0 && encode_config->near_lossless <= 100){
68
+ config.near_lossless = encode_config->near_lossless;
69
+ config.lossless = 1; // use near-lossless only with lossless
70
+ }
67
71
  if (encode_config->quality >= 0 && encode_config->quality <= 100){
68
72
  config.quality = encode_config->quality;
69
73
  }
@@ -288,4 +292,4 @@ int test_c(int n) {
288
292
 
289
293
  #if defined(__cplusplus) || defined(c_plusplus)
290
294
  } // extern "C"
291
- #endif
295
+ #endif
@@ -7,6 +7,7 @@ extern "C" {
7
7
 
8
8
  typedef struct {
9
9
  int lossless; // Lossless encoding (0=lossy(default), 1=lossless).
10
+ int near_lossless; // use near-lossless image preprocessing (0..100=off)
10
11
  float quality; // between 0 (smallest file) and 100 (biggest)
11
12
  int method; // quality/speed trade-off (0=fast, 6=slower-better)
12
13
 
@@ -42,7 +43,7 @@ extern "C" {
42
43
  int crop_x, crop_y, crop_w, crop_h;
43
44
  int resize_w, resize_h;
44
45
  } FfiWebpEncodeConfig;
45
-
46
+
46
47
  typedef struct {
47
48
  OutputFileFormat output_format;
48
49
  int bypass_filtering; // if true, skip the in-loop filtering
@@ -51,7 +52,7 @@ extern "C" {
51
52
  int resize_w, resize_h;
52
53
  int use_threads; // if true, use multi-threaded decoding
53
54
  } FfiWebpDecodeConfig;
54
-
55
+
55
56
 
56
57
  void decoder_version(char *version);
57
58
  void encoder_version(char *version);
@@ -64,4 +65,4 @@ extern "C" {
64
65
  } // extern "C"
65
66
  #endif
66
67
 
67
- #endif /* _WEBP_FFI_H_ */
68
+ #endif /* _WEBP_FFI_H_ */
data/lib/webp/c.rb CHANGED
@@ -12,6 +12,7 @@ module WebP
12
12
  # struct
13
13
  class FfiWebpEncodeConfig < FFI::Struct
14
14
  layout :lossless, :int,
15
+ :near_lossless, :int,
15
16
  :quality, :float,
16
17
  :method, :int,
17
18
  :target_size, :int,
data/lib/webp/options.rb CHANGED
@@ -8,7 +8,7 @@ module WebP
8
8
  def encode_pointer
9
9
  options_pointer = FFI::MemoryPointer.new :char, C::FfiWebpEncodeConfig.size, false
10
10
  options_struct = C::FfiWebpEncodeConfig.new options_pointer
11
- [:lossless, :method, :target_size, :target_PSNR, :segments,
11
+ [:lossless, :near_lossless, :method, :target_size, :target_PSNR, :segments,
12
12
  :sns_strength, :filter_strength, :filter_sharpness,
13
13
  :filter_type, :autofilter, :alpha_compression, :alpha_filtering,
14
14
  :alpha_quality, :pass, :show_compressed, :preprocessing, :partitions,
data/lib/webp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module WebP
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
data/spec/travis_build.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #/usr/bin/env sh
2
- wget http://downloads.webmproject.org/releases/webp/libwebp-0.4.2.tar.gz
3
- tar xvzf libwebp-0.4.2.tar.gz
4
- cd libwebp-0.4.2
2
+ wget http://downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
3
+ tar xvzf libwebp-1.0.2.tar.gz
4
+ cd libwebp-1.0.2
5
5
  ./configure --prefix=$HOME/opt
6
6
  make && make install
@@ -81,6 +81,12 @@ describe WebP do
81
81
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.png.webp"))
82
82
  expect(WebP.encode(in_filename, out_filename)).to be_truthy
83
83
  end
84
+
85
+ it "#{image}.png image with near_lossless" do
86
+ in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.png"))
87
+ out_filename = File.expand_path(File.join(@out_dir, "#{image}_near_lossless.png.webp"))
88
+ expect(WebP.encode(in_filename, out_filename, near_lossless: 60)).to be_truthy
89
+ end
84
90
  end
85
91
  factories[:jpg].each do |image|
86
92
  it "#{image}.jpg image" do
@@ -88,6 +94,12 @@ describe WebP do
88
94
  out_filename = File.expand_path(File.join(@out_dir, "#{image}.jpg.webp"))
89
95
  expect(WebP.encode(in_filename, out_filename)).to be_truthy
90
96
  end
97
+
98
+ it "#{image}.jpg image with near_lossless" do
99
+ in_filename = File.expand_path(File.join(File.dirname(__FILE__), "factories/#{image}.jpg"))
100
+ out_filename = File.expand_path(File.join(@out_dir, "#{image}_near_lossless.jpg.webp"))
101
+ expect(WebP.encode(in_filename, out_filename, near_lossless: 60)).to be_truthy
102
+ end
91
103
  end
92
104
  factories[:tiff].each do |image|
93
105
  it "#{image}.tif image" do
@@ -176,4 +188,4 @@ describe WebP do
176
188
  end
177
189
  end
178
190
 
179
- end
191
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webp-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vasyliev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2019-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.2.2
152
+ rubygems_version: 2.7.6
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: Ruby wrapper for libwebp