Skip to content

Commit

Permalink
Update LibVips and default backend to LibVips
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Mar 18, 2021
1 parent 891d8e6 commit d8503b2
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 109 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.byebug_history
Gemfile.lock
66 changes: 0 additions & 66 deletions Gemfile.lock

This file was deleted.

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion bob_ross.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]
s.homepage = ""
Expand Down
2 changes: 1 addition & 1 deletion lib/bob_ross.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def configure(options)
end

def backend
@backend || BobRoss::ImageMagickBackend
@backend || BobRoss::LibVipsBackend
end

def register_plugin(plugin)
Expand Down
24 changes: 12 additions & 12 deletions lib/bob_ross/backends/libvips.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Ensure ruby-vips > 2.1 is required
gem 'ruby-vips', '>= 2.1'
require 'ruby-vips'

module BobRoss::LibVipsBackend
Expand Down Expand Up @@ -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] == '#'
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions lib/bob_ross/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module ActiveRecord
module Filter
VERSION = '1.0.0'
end
class BobRoss
VERSION = '2.0.0'
end
38 changes: 19 additions & 19 deletions test/bob_ross/image_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,31 +264,31 @@ class BobRossImageTest < Minitest::Test
geometry: '100x67',
signature: [
'b8428b80e19b60f18037e90f35de035b93f83c6f3bfd09ef4e088e2e6b7b8da1',
'17e82e94829727ea951a43f5d7b00b4ed2037813832325e29a12fbb51298efa6'
'c39e3f0612cdf56c3354d632e9dbbb7bcc8bd8408b19d7cd226126e744115aaa'
]
})

assert_transform(image, {resize: 'x100'}, {
geometry: '150x100',
signature: [
'6a119768c3135cfc8cd340fe273f765518512e99097da0961b7b80eb885a4e24',
'7afdf2d51e6770a844394eac2611fe0e6d0cc11d5a7df6405e72831bfe58d104'
'ba2a72f86332cf5f0bc2146040d1925b340a22ab831a352ec5e713379ee1c108'
]
})

assert_transform(image, {resize: '100x100'}, {
geometry: '100x67',
signature: [
'b8428b80e19b60f18037e90f35de035b93f83c6f3bfd09ef4e088e2e6b7b8da1',
'17e82e94829727ea951a43f5d7b00b4ed2037813832325e29a12fbb51298efa6'
'c39e3f0612cdf56c3354d632e9dbbb7bcc8bd8408b19d7cd226126e744115aaa'
]
})

assert_transform(image, {resize: '100x100!'}, {
geometry: '100x100',
signature: [
'b6a9cbf02cf05ba5ea6531daa6084b181ab30f5a0a078b224241297fa19619af',
'f7734eebb6923e6737228dec08ea38924ebca57846e25557cbfbd0db8e500658'
'bb90253f26775ec23e90c4465306da6a4ac1e1b18f4c14f1b1286b263373c885'
]
})

Expand All @@ -304,15 +304,15 @@ class BobRossImageTest < Minitest::Test
geometry: '200x133',
signature: [
'04e2b2b059aba5fa0a094fc9e96019e19502396dce8c411c5f82a29de70db96a',
'21846e78dd4b5ac2d488c108cd7ccce5c80faaed9111445c88dccb8009eb0233'
'53446dc48de4b954252e9ca03a3022fb05cf1dab24b0cd2f5e89e2f6f5084b58'
]
})

assert_transform(image, {resize: '800x800<'}, {
geometry: '800x533',
signature: [
'308bb6ded0c87e2d28055f962e1a13123393593baca8f173b03b31bb33e09f2e',
'927ff8fee09ad3c4a9396164bfa36bde12f89ffd58f596ef39d52c74c31332b6'
'500151ddb81f612a7416665d39513d032b93f9bfcccd8fd5240289cc171a1f9a'
]
})

Expand All @@ -328,23 +328,23 @@ class BobRossImageTest < Minitest::Test
geometry: '200x200',
signature: [
'69a200e57445da54086a78838252ae24b9b9e6c1f0e3496368fb0be89ae73bc4',
'3f3f34ece66faa71b52f51ecd288b7d4235dfc0276bc874a6cb4792ddc8e59c5'
'6cbf8367ca117379cbe93f4d7e1da51d9def5910f42fe6f863b6145ab692f081'
]
})

assert_transform(image, {resize: '200x200*'}, {
geometry: '200x200',
signature: [
'f3209ac875fef39f31c0746cda7b80a65a05432534754cc7f6616d34128dc342',
'814015550d78533c3618d88fdc3387c5e40b2f84cf9edd92b9b51a7344be8c8a'
'9603566efc107c75c7e48bba736ff5c2e73639c6bb9d7c541ccc0b6d2f5e8904'
]
})

assert_transform(image, {resize: '200x200*w'}, {
geometry: '200x200',
signature: [
'f887e8e7c293970bd73f3880395e2d03b9adfcd222b24331c95fa5bc679c5127',
'07529580c65888db633bab7d42ed0a0fc9a74889043c91b5743cf84bd655bb46'
'58ddee7ed63418c00da0502bb9e7917c164e1275d155bdff8b2feac0e16a280c'
]
})
end
Expand All @@ -359,79 +359,79 @@ class BobRossImageTest < Minitest::Test
geometry: '720x480',
signature: [
'5a0b0ab61d3b4cbfd32eb7f2a273c3050dbee50504544b66158fca1b7c2a90f4',
'9e10618d2111055cd6e7cef0a8b46513c69ef79d2abd346b0ca8f9ffba80b705'
'db980c1fce16fd9067ec40f700f88ac6b869dc1106ec03829c8ad87bfd2c03c8'
]
})

assert_transform(image, {watermark: '0e'}, {
geometry: '720x480',
signature: [
'77830c630bc2b525a6eab6dc21c29867bf8ed94736ad9f286c0b3a14467dc7af',
'2768d68cb31bf95cff3a23e66e534f813599d4a015f2abd578300026fe50a1a1'
'cd086f2d95bc20750aab6403bf9035b7b6b5ec0253c39a0702794554d39d5625'
]
})

assert_transform(image, {watermark: '0s'}, {
geometry: '720x480',
signature: [
'c69a96ee3caf1088bab040d5d90eb77b295c9fdbe8b99838eb124e4b9dcd2393',
'3d5c9e8dae96200394428a108bb2ed76e3632dafe0f0412dd1d27f95ed6e4ff0'
'1ee816239f17bf0ff6d041b4981726a0e68b0cbef774472ceec848477ade71f2'
]
})

assert_transform(image, {watermark: '0w'}, {
geometry: '720x480',
signature: [
'7dac6b13a596cfaa4649f397c13e2edcf12e9e53e32df86c0a3567efe2ba8f7a',
'9d76d0c2661a03f383a25d3719167a16022b13eef28e44bc9ea85ceff8ff441c'
'0967a51465835ca28aabd5830d01568c28faa3748cfb162e865d23014a4965df'
]
})

assert_transform(image, {watermark: '0c'}, {
geometry: '720x480',
signature: [
'210c9b8732def89f30b49e14a00ba21f4dcb35e7773605a9b386656fad158521',
'1f2303e60f53b37a635dd81e56c730d67594376239b22190fac9e303907082ce'
'2e53eb526688724611c4ed032d0ac3cc4385bef04ede764df8e7877379ab601c'
]
})

assert_transform(image, {watermark: '0ne'}, {
geometry: '720x480',
signature: [
'd29c63e1a86a5d196c04d86cf47a755f37e659571390695662e3a9f112b4b606',
'16a30429b6e4dfc4a1d1f697419f3f3dde193adb0e666c8017b3d367dd26e605'
'6db451d0ff46afad134c46d838bb673843110e96206337d07c8990b0f92a8a2c'
]
})

assert_transform(image, {watermark: '0se'}, {
geometry: '720x480',
signature: [
'd818279a67ab1a67f8adc107e53f4e826b46ffb9a92cdfc50a77c6978d049bb2',
'ec2dc0beda26c3681445b121571c16763cd73343042e84833a1c36b84178bb7b'
'c3cccfcd8496273e6da69e4c002e99a6c0f1acd7464405e3a5ff9488aca75283'
]
})

assert_transform(image, {watermark: '0sw'}, {
geometry: '720x480',
signature: [
'bf30cbdb4a28347aab4e8e58bf8289392c7d7527e263ed6b6232674e40dc071b',
'8f9f2f05123373287626c40990889b68c6e5a4e1cf4de35e916c1a50e80f7bd0'
'e5781c478e9a694ca0fef137bf340660635178127e5611c84824aaaa87f50bea'
]
})

assert_transform(image, {watermark: '0nw'}, {
geometry: '720x480',
signature: [
'b203550e214d3035e97202b57b72bbc4525b7bafbb71b1130f4ce0c411268dfd',
'808940ed1ca20ef6f831793565850c3ce46011f1d036ad41a657cfa4222746d2'
'1593edfca341c4b6a9e3fa0466d94da68d6f53bf79e083d50ae1e86fcdee7c84'
]
})

assert_transform(image, {watermark: '0o'}, {
geometry: '720x480',
signature: [
'add7d6ea1fc4ae3ebd0a80f2d40dedfc07fd5a382981c5de063ad062b15de238',
'9a0b71ee3ee50328145e8368c90d233240e19cf1ec5c4526027784d900fccc88'
'4f798c285d89c346a4931b87338bbc76ab14242d027e677d65cb15938bfe5a0d'
]
})
end
Expand Down
8 changes: 4 additions & 4 deletions test/bob_ross/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d8503b2

Please sign in to comment.