147 Commits

Author SHA1 Message Date
Geremia Taglialatela 682a32cd46 Fix typos (#126) 2024-07-25 09:42:06 +02:00
Janko Marohnić 4cc044087e Revert "Don't allow calling Kernel methods via loader/saver options"
It doesn't fully resolve the security vulnerability, and there is no
point in only partially resolving it.

See https://github.com/janko/image_processing/issues/100

This reverts commit aed5b80cd7.
2024-07-24 18:48:04 +02:00
Janko Marohnić 84e5b61fcc Still support -append in MiniMagick 2024-06-15 23:19:48 +02:00
Janko Marohnić 9d72e46bce Support resize-on-load for resize to cover
We can now rename it back to `#resize_to_cover`, since vips backend
requires all `resize_to_*` operations to support resize-on-load.
2024-06-15 23:10:03 +02:00
Brendon Muir 8c85ad9252 Add resize_to_cover (#120)
* 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
2024-06-06 12:02:29 +02:00
Petrik de Heus 843a859e12 Fix failing test (#117)
The following test currently fails on CI:

   1) Failure:
      ImageProcessing::Vips::#resize_and_pad#test_0006_accepts thumbnail
      options [/home/runner/work/image_processing/image_processing/test/vips_test.rb:310]:
      Expected 1 to be > 3.

By using `:entropy` instead of `:centre` the images differ more
according to DHash.
2023-09-24 15:53:28 +02:00
Vít Ondruch 709bcf7eec Fix compatibility with Minitest 5.19+ (#114)
The `MiniTest` was renamed to `Minitest`:

https://github.com/minitest/minitest/commit/9a57c520ceac76abfe6105866f8548a94eb357b6

And the `MiniTest` constant is now loaded just when `MT_COMPAT` environment variable is set:

https://github.com/minitest/minitest/commit/a2c6c18570f6f0a1bf6af70fe3b6d9599a13fdd6

This fixes following issue:

~~~
$ ruby -Ilib:test -e 'Dir.glob "./test/**/*_test.rb", &method(:require)'
/builddir/build/BUILD/test/test_helper.rb:17:in `<top (required)>': uninitialized constant MiniTest (NameError)
class MiniTest::Test
      ^^^^^^^^
Did you mean?  Minitest
	from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /builddir/build/BUILD/image_processing-1.12.2/usr/share/gems/gems/image_processing-1.12.2/test/builder_test.rb:1:in `<top (required)>'
	from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:dir>:220:in `glob'
	from -e:1:in `<main>'
~~~
2023-08-31 14:10:34 +02:00
Janko Marohnić aed5b80cd7 Don't allow calling Kernel methods via loader/saver options 2022-07-31 16:48:01 +02:00
Janko Marohnić 038e4574e8 Prevent remote shell execution in #apply
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`.
2022-03-01 22:15:04 +01:00
Janko Marohnić f0c152e83b Replace Phashion with dhash-vips
Phashion currently doesn't install on Apple Silicon, and it doesn't seem
it's going to get fixed.

An upside is that this will now work on JRuby as well, since dhash-vips
doesn't use C extensions.
2021-09-26 10:39:56 +02:00
Janko Marohnić b2b91dff6a Account for different error messages 2021-09-26 10:28:55 +02:00
Janko Marohnić 0d0d9a41ee Move from Travis CI to GitHub CI (#93)
* Move from Travis CI to GitHub CI

* Update error message

* Fix Ruby 2.3 compatibility
2021-09-12 21:42:53 +02:00
Bastian Bartmann 3db009a68b Fix format fallback for files ending in with a dot (#73)
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.
2020-11-06 16:11:11 +01:00
Janko Marohnić 04227125bd Add instrumentation support
Closes #70
2020-09-20 21:19:50 +02:00
Janko Marohnić fb52ea0611 [minimagick] Handle destination path without file extension
Closes #66
2020-05-17 10:02:23 +02:00
Janko Marohnić 7cd4058e14 [minimagick] Add #crop with left, top, width, height arguments
This allows us to replace

  crop("300x300+0+50")

with

  crop(0, 50, 300, 300)

This matches the existing libvips' vips_crop() arguments.
2020-05-17 09:30:25 +02:00
Janko Marohnić 5052cc5526 [vips] Fix auto-rotation bug on libvips 8.9.0
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
2020-01-12 20:40:36 +01:00
Ryuta Kamizono 59ce62b703 Fix Ruby 2.7 warnings (#63)
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>
2020-01-11 15:54:11 +01:00
Janko Marohnić 8b48f2e919 [minimagick] Add :loader for explicitly setting input file type
By default, ImageMagick guesses the input file type based on magic
headers and other information. However, it's not always possible for
ImageMagick to correctly identify the file based on its content, and in
some cases it can be a security flaw. So, ImageMagick gives you the
ability to explicitly set the input file type.

  convert jpg:input.jpg ...

The vips backend already provides the equivalent :loader option, so we
use the same name for the minimagick counterpart as well.

  ImageProcessing::MiniMagick
    .source("input.jpg")
    .loader(loader: "jpg")
    # ...
2019-12-18 16:54:03 +01:00
Ken Collins 94cb7239aa Use Int Precision w/Vips During Sharpen (#56)
Work in #22 added automatic image sharpening for Vips. However, discovered in #55 `conv()` defaults to float precision and can leave to visual artifacts in some scenarios. Per @jcupitt recommendation, we can add `precision: :integer` to conv and this should also give us a speed-up, since int convolutions will use SIMD. https://github.com/janko/image_processing/issues/55

Fixes #55
2019-08-11 20:49:24 +02:00
Janko Marohnić 6510978cd0 Fix test not working on Vips 8.8
It seems that vips_thumbnail() doesn't accept the :auto_rotate option
anymore.
2019-07-20 12:56:10 +02:00
Janko Marohnić cf0eafc264 [vips] Verify that resize-on-load autorotates 2019-05-19 16:07:32 +02:00
Janko Marohnić f0256f8574 Attempt to fix tests on Travis
On Travis libvips isn't installed with WebP support, so we try using a
different loader and saver.
2019-04-09 09:45:08 +02:00
Janko Marohnić 4927d40c83 [vips] Allow forcing a specific loader or saver
Sometimes libvips is not able to identify the source image type, even if
there is a corresponding loader. In this case it's useful to be able to
tell libvips which loader to use. So, we add a `:loader` option that
does just that:

  ImageProcessing::Vips
    .loader(loader: :svg) # calls `Vips::Image.svgload`
    # ...

For symmetry, we also add a `:saver` option, just in case libvips isn't
able to correctly identify the file extension of the destination path.

  ImageProcessing::Vips
    .saver(saver: :tiff) # calls `Vips::Image#tiffsave`
    # ...

Closes #49
2019-04-09 01:07:31 +02:00
Janko Marohnić 3c9c0922b8 [vips] Perform resize-on-load when possible
Resizing on load using `vips_thumbnail()` (versus after load using
`vips_thumbnail_image()`) can speed up resizing significantly, and in
some cases even make it more accurate.

  thumbnail_image() (1000px => 300px) – 0.062s
  thumbnail()       (1000px => 300px) – 0.031s

  thumbnail_image() (1000px => 500px) – 0.045s
  thumbnail()       (1000px => 500px) – 0.043s

  thumbnail_image() (1000px => 800px) – 0.046s
  thumbnail()       (1000px => 800px) – 0.043s

  thumbnail_image() (1500px => 300px) – 0.104s
  thumbnail()       (1500px => 300px) – 0.037s

  thumbnail_image() (1500px => 500px) – 0.096s
  thumbnail()       (1500px => 500px) – 0.068s

  thumbnail_image() (1500px => 800px) – 0.090s
  thumbnail()       (1500px => 800px) – 0.066s

  thumbnail_image() (2000px => 300px) – 0.154s
  thumbnail()       (2000px => 300px) – 0.041s

  thumbnail_image() (2000px => 500px) – 0.170s
  thumbnail()       (2000px => 500px) – 0.051s

  thumbnail_image() (2000px => 800px) – 0.147s
  thumbnail()       (2000px => 800px) – 0.093s

  thumbnail_image() (2500px => 300px) – 0.219s
  thumbnail()       (2500px => 300px) – 0.046s

  thumbnail_image() (2500px => 500px) – 0.218s
  thumbnail()       (2500px => 500px) – 0.053s

  thumbnail_image() (2500px => 800px) – 0.215s
  thumbnail()       (2500px => 800px) – 0.123s

  thumbnail_image() (3000px => 300px) – 0.300s
  thumbnail()       (3000px => 300px) – 0.046s

  thumbnail_image() (3000px => 500px) – 0.310s
  thumbnail()       (3000px => 500px) – 0.076s

  thumbnail_image() (3000px => 800px) – 0.302s
  thumbnail()       (3000px => 800px) – 0.146s

Closes #48
2019-02-25 10:45:47 +01:00