From d8503b2489e4ea3ce63c399fa31e18a9b090f3ee Mon Sep 17 00:00:00 2001 From: Jon Bracy Date: Thu, 18 Mar 2021 15:36:42 -0500 Subject: [PATCH] Update LibVips and default backend to LibVips --- .gitignore | 1 + Gemfile.lock | 66 -------------------------------- README.md | 10 ++++- bob_ross.gemspec | 2 +- lib/bob_ross.rb | 2 +- lib/bob_ross/backends/libvips.rb | 24 ++++++------ lib/bob_ross/version.rb | 6 +-- test/bob_ross/image_test.rb | 38 +++++++++--------- test/bob_ross/server_test.rb | 8 ++-- 9 files changed, 48 insertions(+), 109 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index cba43f7..c9888c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store .byebug_history +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 6992aeb..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,66 +0,0 @@ -PATH - remote: . - specs: - bob_ross (1) - mini_mime - sqlite3 - terrapin - -GEM - remote: https://rubygems.org/ - specs: - activesupport (6.0.3.2) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - ansi (1.5.0) - builder (3.2.4) - byebug (11.1.3) - climate_control (0.2.0) - concurrent-ruby (1.1.6) - ffi (1.13.1) - i18n (1.8.5) - concurrent-ruby (~> 1.0) - mini_mime (1.0.2) - minitest (5.14.1) - minitest-reporters (1.4.2) - ansi - builder - minitest (>= 5.0) - ruby-progressbar - mocha (1.11.2) - rack (2.2.3) - rake (13.0.1) - ruby-progressbar (1.10.1) - ruby-vips (2.0.17) - ffi (~> 1.9) - sqlite3 (1.4.2) - standardstorage (1.0.2) - terrapin - terrapin (0.6.0) - climate_control (>= 0.0.3, < 1.0) - thread_safe (0.3.6) - tzinfo (1.2.7) - thread_safe (~> 0.1) - zeitwerk (2.4.0) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport - bob_ross! - bundler - byebug - minitest - minitest-reporters - mocha - rack - rake - ruby-vips - standardstorage - -BUNDLED WITH - 1.17.3 diff --git a/README.md b/README.md index 97937e1..86bf8d9 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,14 @@ The BobRoss server depends on the following: Optionally: + - `libheif` to support the [HEIC](https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format) + image format. - `libwebp` to support the [WEBP](https://en.wikipedia.org/wiki/WebP) image format. - `jxrlib` to support the [JPEG XR](https://en.wikipedia.org/wiki/JPEG_XR) image format. + - `giflib` for GIF support in LibVips. + - `libjpeg-turbo` for faster JPEG encoding/decoding. - The `sqlite3` gem to use a local disk cache. - `mupdf-tools` for PDF support @@ -397,6 +401,8 @@ Amount of disk size in bytes to use for the cache. Default is `1.gigabyte` ## Plugins -BobRoss can process any image format that ImageMagick accepts. To process other types of files and turn them into images that BobRoss can use.you can use +BobRoss can process any image format that ImageMagick or LibVips accepts. + +To process other types of files and turn them into images that BobRoss can create a plugin. -BobRoss also +For an example see `lib/bob_ross/plugins/pdf`. \ No newline at end of file diff --git a/bob_ross.gemspec b/bob_ross.gemspec index b3b8ead..de1866d 100644 --- a/bob_ross.gemspec +++ b/bob_ross.gemspec @@ -2,7 +2,7 @@ require_relative "lib/bob_ross/version" Gem::Specification.new do |s| s.name = "bob_ross" - s.version = 1 + s.version = BobRoss::VERSION s.authors = ["Jon Bracy"] s.email = ["jonbracy@gmail.com"] s.homepage = "" diff --git a/lib/bob_ross.rb b/lib/bob_ross.rb index 9773318..0232ae7 100644 --- a/lib/bob_ross.rb +++ b/lib/bob_ross.rb @@ -30,7 +30,7 @@ def configure(options) end def backend - @backend || BobRoss::ImageMagickBackend + @backend || BobRoss::LibVipsBackend end def register_plugin(plugin) diff --git a/lib/bob_ross/backends/libvips.rb b/lib/bob_ross/backends/libvips.rb index 40d27c0..df8730f 100644 --- a/lib/bob_ross/backends/libvips.rb +++ b/lib/bob_ross/backends/libvips.rb @@ -1,3 +1,5 @@ +# Ensure ruby-vips > 2.1 is required +gem 'ruby-vips', '>= 2.1' require 'ruby-vips' module BobRoss::LibVipsBackend @@ -69,10 +71,7 @@ def resize(image, vips, geometry) :both end - vips = vips.thumbnail_image(geometry[:width], { - height: geometry[:height], - size: modifier - }) + vips = vips.thumbnail_image(geometry[:width], height: geometry[:height], size: modifier) vips = vips.conv(SHARPEN_MASK) if image.area > (vips.width * vips.height) if geometry[:modifier] == '#' @@ -137,16 +136,16 @@ def crop(vips, geometry) end def pad(vips, padding) - vips.embed(padding[:left], padding[:top], vips.width + padding[:right] + padding[:left], vips.height + padding[:bottom] + padding[:top], { + vips.embed(padding[:left], padding[:top], vips.width + padding[:right] + padding[:left], vips.height + padding[:bottom] + padding[:top], extend: :background, background: rgba_to_values(padding[:color] || '#00000000', bands: vips.bands) - }) + ) end def background(image, vips, background_color) bg_color = rgba_to_values(background_color, bands: vips.bands) background = vips.new_from_image(bg_color) - vips = background.composite(vips, :over) + background.composite(vips, :over) end def watermark(image, vips, transform) @@ -171,8 +170,8 @@ def watermark(image, vips, transform) geometry[:height] = geometry[:width] end end - wtrmrk = ::Vips::Image.new_from_file(watermark_file[:path], select_valid_loader_options(watermark_file[:path], {})) - wtrmrk = wtrmrk.thumbnail_image(geometry[:width], {height: geometry[:height]}) + wtrmrk = ::Vips::Image.new_from_file(watermark_file[:path], **select_valid_loader_options(watermark_file[:path], {})) + wtrmrk = wtrmrk.thumbnail_image(geometry[:width], height: geometry[:height]) geometry[:height] = wtrmrk.height geometry[:width] = wtrmrk.width @@ -259,8 +258,9 @@ def watermark(image, vips, transform) end def transform(image, transformations, options) - vips = ::Vips::Image.new_from_file(image.source.path, select_valid_loader_options(image.source.path, {})) - + vips = ::Vips::Image.new_from_file(image.source.path, **select_valid_loader_options(image.source.path, {})) + + if image.orientation vips = case image.orientation when 2 @@ -320,7 +320,7 @@ def transform(image, transformations, options) # end # transformations.delete(:lossless) - vips.write_to_file(output.path, select_valid_saver_options(output.path, {})) + vips.write_to_file(output.path, **select_valid_saver_options(output.path, {})) output end diff --git a/lib/bob_ross/version.rb b/lib/bob_ross/version.rb index 26295de..266650b 100644 --- a/lib/bob_ross/version.rb +++ b/lib/bob_ross/version.rb @@ -1,5 +1,3 @@ -module ActiveRecord - module Filter - VERSION = '1.0.0' - end +class BobRoss + VERSION = '2.0.0' end diff --git a/test/bob_ross/image_test.rb b/test/bob_ross/image_test.rb index 28bc985..4beed7f 100644 --- a/test/bob_ross/image_test.rb +++ b/test/bob_ross/image_test.rb @@ -264,7 +264,7 @@ class BobRossImageTest < Minitest::Test geometry: '100x67', signature: [ 'b8428b80e19b60f18037e90f35de035b93f83c6f3bfd09ef4e088e2e6b7b8da1', - '17e82e94829727ea951a43f5d7b00b4ed2037813832325e29a12fbb51298efa6' + 'c39e3f0612cdf56c3354d632e9dbbb7bcc8bd8408b19d7cd226126e744115aaa' ] }) @@ -272,7 +272,7 @@ class BobRossImageTest < Minitest::Test geometry: '150x100', signature: [ '6a119768c3135cfc8cd340fe273f765518512e99097da0961b7b80eb885a4e24', - '7afdf2d51e6770a844394eac2611fe0e6d0cc11d5a7df6405e72831bfe58d104' + 'ba2a72f86332cf5f0bc2146040d1925b340a22ab831a352ec5e713379ee1c108' ] }) @@ -280,7 +280,7 @@ class BobRossImageTest < Minitest::Test geometry: '100x67', signature: [ 'b8428b80e19b60f18037e90f35de035b93f83c6f3bfd09ef4e088e2e6b7b8da1', - '17e82e94829727ea951a43f5d7b00b4ed2037813832325e29a12fbb51298efa6' + 'c39e3f0612cdf56c3354d632e9dbbb7bcc8bd8408b19d7cd226126e744115aaa' ] }) @@ -288,7 +288,7 @@ class BobRossImageTest < Minitest::Test geometry: '100x100', signature: [ 'b6a9cbf02cf05ba5ea6531daa6084b181ab30f5a0a078b224241297fa19619af', - 'f7734eebb6923e6737228dec08ea38924ebca57846e25557cbfbd0db8e500658' + 'bb90253f26775ec23e90c4465306da6a4ac1e1b18f4c14f1b1286b263373c885' ] }) @@ -304,7 +304,7 @@ class BobRossImageTest < Minitest::Test geometry: '200x133', signature: [ '04e2b2b059aba5fa0a094fc9e96019e19502396dce8c411c5f82a29de70db96a', - '21846e78dd4b5ac2d488c108cd7ccce5c80faaed9111445c88dccb8009eb0233' + '53446dc48de4b954252e9ca03a3022fb05cf1dab24b0cd2f5e89e2f6f5084b58' ] }) @@ -312,7 +312,7 @@ class BobRossImageTest < Minitest::Test geometry: '800x533', signature: [ '308bb6ded0c87e2d28055f962e1a13123393593baca8f173b03b31bb33e09f2e', - '927ff8fee09ad3c4a9396164bfa36bde12f89ffd58f596ef39d52c74c31332b6' + '500151ddb81f612a7416665d39513d032b93f9bfcccd8fd5240289cc171a1f9a' ] }) @@ -328,7 +328,7 @@ class BobRossImageTest < Minitest::Test geometry: '200x200', signature: [ '69a200e57445da54086a78838252ae24b9b9e6c1f0e3496368fb0be89ae73bc4', - '3f3f34ece66faa71b52f51ecd288b7d4235dfc0276bc874a6cb4792ddc8e59c5' + '6cbf8367ca117379cbe93f4d7e1da51d9def5910f42fe6f863b6145ab692f081' ] }) @@ -336,7 +336,7 @@ class BobRossImageTest < Minitest::Test geometry: '200x200', signature: [ 'f3209ac875fef39f31c0746cda7b80a65a05432534754cc7f6616d34128dc342', - '814015550d78533c3618d88fdc3387c5e40b2f84cf9edd92b9b51a7344be8c8a' + '9603566efc107c75c7e48bba736ff5c2e73639c6bb9d7c541ccc0b6d2f5e8904' ] }) @@ -344,7 +344,7 @@ class BobRossImageTest < Minitest::Test geometry: '200x200', signature: [ 'f887e8e7c293970bd73f3880395e2d03b9adfcd222b24331c95fa5bc679c5127', - '07529580c65888db633bab7d42ed0a0fc9a74889043c91b5743cf84bd655bb46' + '58ddee7ed63418c00da0502bb9e7917c164e1275d155bdff8b2feac0e16a280c' ] }) end @@ -359,7 +359,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ '5a0b0ab61d3b4cbfd32eb7f2a273c3050dbee50504544b66158fca1b7c2a90f4', - '9e10618d2111055cd6e7cef0a8b46513c69ef79d2abd346b0ca8f9ffba80b705' + 'db980c1fce16fd9067ec40f700f88ac6b869dc1106ec03829c8ad87bfd2c03c8' ] }) @@ -367,7 +367,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ '77830c630bc2b525a6eab6dc21c29867bf8ed94736ad9f286c0b3a14467dc7af', - '2768d68cb31bf95cff3a23e66e534f813599d4a015f2abd578300026fe50a1a1' + 'cd086f2d95bc20750aab6403bf9035b7b6b5ec0253c39a0702794554d39d5625' ] }) @@ -375,7 +375,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ 'c69a96ee3caf1088bab040d5d90eb77b295c9fdbe8b99838eb124e4b9dcd2393', - '3d5c9e8dae96200394428a108bb2ed76e3632dafe0f0412dd1d27f95ed6e4ff0' + '1ee816239f17bf0ff6d041b4981726a0e68b0cbef774472ceec848477ade71f2' ] }) @@ -383,7 +383,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ '7dac6b13a596cfaa4649f397c13e2edcf12e9e53e32df86c0a3567efe2ba8f7a', - '9d76d0c2661a03f383a25d3719167a16022b13eef28e44bc9ea85ceff8ff441c' + '0967a51465835ca28aabd5830d01568c28faa3748cfb162e865d23014a4965df' ] }) @@ -391,7 +391,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ '210c9b8732def89f30b49e14a00ba21f4dcb35e7773605a9b386656fad158521', - '1f2303e60f53b37a635dd81e56c730d67594376239b22190fac9e303907082ce' + '2e53eb526688724611c4ed032d0ac3cc4385bef04ede764df8e7877379ab601c' ] }) @@ -399,7 +399,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ 'd29c63e1a86a5d196c04d86cf47a755f37e659571390695662e3a9f112b4b606', - '16a30429b6e4dfc4a1d1f697419f3f3dde193adb0e666c8017b3d367dd26e605' + '6db451d0ff46afad134c46d838bb673843110e96206337d07c8990b0f92a8a2c' ] }) @@ -407,7 +407,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ 'd818279a67ab1a67f8adc107e53f4e826b46ffb9a92cdfc50a77c6978d049bb2', - 'ec2dc0beda26c3681445b121571c16763cd73343042e84833a1c36b84178bb7b' + 'c3cccfcd8496273e6da69e4c002e99a6c0f1acd7464405e3a5ff9488aca75283' ] }) @@ -415,7 +415,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ 'bf30cbdb4a28347aab4e8e58bf8289392c7d7527e263ed6b6232674e40dc071b', - '8f9f2f05123373287626c40990889b68c6e5a4e1cf4de35e916c1a50e80f7bd0' + 'e5781c478e9a694ca0fef137bf340660635178127e5611c84824aaaa87f50bea' ] }) @@ -423,7 +423,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ 'b203550e214d3035e97202b57b72bbc4525b7bafbb71b1130f4ce0c411268dfd', - '808940ed1ca20ef6f831793565850c3ce46011f1d036ad41a657cfa4222746d2' + '1593edfca341c4b6a9e3fa0466d94da68d6f53bf79e083d50ae1e86fcdee7c84' ] }) @@ -431,7 +431,7 @@ class BobRossImageTest < Minitest::Test geometry: '720x480', signature: [ 'add7d6ea1fc4ae3ebd0a80f2d40dedfc07fd5a382981c5de063ad062b15de238', - '9a0b71ee3ee50328145e8368c90d233240e19cf1ec5c4526027784d900fccc88' + '4f798c285d89c346a4931b87338bbc76ab14242d027e677d65cb15938bfe5a0d' ] }) end diff --git a/test/bob_ross/server_test.rb b/test/bob_ross/server_test.rb index 8c42e23..ba3b39a 100644 --- a/test/bob_ross/server_test.rb +++ b/test/bob_ross/server_test.rb @@ -186,18 +186,18 @@ def create_server(configs={}) response = server.get("/flyer") assert_equal 'image/jpeg', response.headers['Content-Type'] - assert_includes ['609cbcb0b8852dcf9405be375f99cc30', '78a021579b9e75a03eccb2153f424b79'], Digest::MD5.hexdigest(response.body) + assert_includes ['609cbcb0b8852dcf9405be375f99cc30', '189cc7b799e9fde05de11db2566a42f9'], Digest::MD5.hexdigest(response.body) response = server.get("/S100/floorplan") assert_equal 'image/jpeg', response.headers['Content-Type'] - assert_includes ['1e15e172a07939d31e728ef5fcba105d', '2afe7fc722030521488dac3e1511988b'], Digest::MD5.hexdigest(response.body) + assert_includes ['2afe7fc722030521488dac3e1511988b', '162afccbb48ac9b89ad72667dfca1f1b'], Digest::MD5.hexdigest(response.body) response = server.get("/S50x50/floorplan") assert_equal 'image/jpeg', response.headers['Content-Type'] - assert_includes ['6bf004d745febd8c029c04fc287487b2', '239519dd507688d46f44945913266663'], Digest::MD5.hexdigest(response.body) + assert_includes ['6bf004d745febd8c029c04fc287487b2', 'b4516392568496638fcae8978550131c'], Digest::MD5.hexdigest(response.body) response = server.get("/Sx50/flyer") assert_equal 'image/jpeg', response.headers['Content-Type'] - assert_includes ['a665f53431284af2e58b2e6a4f6bafe9', '9e5419016eca6f936d13cdf1cb99048a'], Digest::MD5.hexdigest(response.body) + assert_includes ['a665f53431284af2e58b2e6a4f6bafe9', '4b6733e19cb870cb7263e7d99b0e0ff0'], Digest::MD5.hexdigest(response.body) end end \ No newline at end of file