lib/capybara/screenshot/diff/drivers/vips_driver.rb in capybara-screenshot-diff-1.6.2 vs lib/capybara/screenshot/diff/drivers/vips_driver.rb in capybara-screenshot-diff-1.6.3

- old
+ new

@@ -67,11 +67,11 @@ def inscribed?(dimensions, i) dimension(i) == dimensions || i.width < dimensions[0] || i.height < dimensions[1] end def crop(dimensions, i) - i.crop(0, 0, *dimensions) + i.crop(*dimensions) end def filter_image_with_median(image, median_filter_window_size) image.median(median_filter_window_size) end @@ -102,11 +102,17 @@ def width_for(image) image.width end + PNG_EXTENSION = ".png" + + # Vips could not work with the same file. Per each process we require to create new file def save_image_to(image, filename) - image.write_to_file(filename) + ::Dir::Tmpname.create([filename, PNG_EXTENSION]) do |tmp_image_filename| + image.write_to_file(tmp_image_filename) + FileUtils.mv(tmp_image_filename, filename) + end end def resize_image_to(image, new_width, new_height) image.resize(1.* new_width / new_height) end