* Add resize_to_cover
* Add an initial resize_to_cover test
* Fix method name and add passing tests for VIPS
* Add cover method for MiniMagick and add tests
* Rearrange VIPS tests to match source code order
* Update CHANGELOG.md
* Add documentation for cover to both engines
If the operations are coming from user input, this could allow the user
to execute arbitrary shell commands via `Kernel#system` and
`Kernel#spawn`:
ImageProcessing::Vips.apply({ system: "echo something" })
We prevent this by using `#public_send` instead of `#send`, which goes
to method missing instead of calling private methods, which include
`Kernel#system` and `Kernel#spawn`.
File.extname was updated in ruby 2.7 to return “.” when the file ends in a dot. Previously it was returning an empty string. This can break determining the destination format.
When performing resizing with loader options, the following gets called
internally:
Vips::Image.new_from_file("/path/to/source.jpg")
.autorot
.thumbnail_image(400, 400)
.write_to_file("/path/to/destination.jpg")
Prior to libvips 8.9.0, this code would produce a correctly auto-rotated
image. However, in libvips 8.9.0, the auto-rotation from `autorot` and
the default auto-rotation performed by `thumbnail_image` cancel each
other out, leaving the image rotated.
We fix this by disabling auto-rotation for the `thumbnail` operation, so
that the only auto-rotation done is by `autorot`. In the resize-on-load
case we leave `thumbnail` to auto-rotate, as in that case `autorot` is
not called beforehand.
Closes#64
Ruby 2.7 introduced warnings around implicit conversions between
kwargs and hashes, so we fix the warnings.
If we have the following method:
def foo(a, b, **c)
end
And we pass arguments like this:
args = [1, 2, { x: :y }]
foo(*args)
This will trigger a kwarg warning on Ruby 2.7. So, we need to explicitly
pass the last argument as kwargs if it is a hash.
Surprisingly, the warning was only triggered when using #apply:
# would trigger the kwargs warning
ImageProcessing::Vips
.source("/path/to/image")
.apply!(resize_to_limit: [400, 400, sharpen: false])
And not when calling operation directly:
# wouldn't trigger the kwargs warning
ImageProcessing::Vips
.source("/path/to/image")
.resize_to_limit!(400, 400, sharpen: false)
Even though final options are exactly the same, so the code that's then
executed on processing should be the same.
options1 = ImageProcessing::Vips
.apply(resize_to_limit: [400, 400, sharpen: false])
options2 = ImageProcessing::Vips
.resize_to_limit(400, 400, sharpen: false)
options1 == options2 #=> true
The warning was coming from Processor.apply_operation when we would call
an underlying macro. It's probably a bug in Ruby, both examples should have
triggered the same warning. But I couldn't isolate it, so instead we
add an additional test case for #apply.
Co-authored-by: Janko Marohnić <janko.marohnic@gmail.com>