Serabe / RMagick4J

RMagick for JRuby.
Other
29 stars 13 forks source link

Magick::Image::write outputs empty files on Windows #27

Open joankaradimov opened 6 years ago

joankaradimov commented 6 years ago

My environment is:

JRuby 9.1.10.0 through 9.1.15.0 Java 8 Windows 10

I initially encountered this using jnormington/dotdiff. After some debugging I came up with a straightforward way to reproduce it in a jirb. Here's what a reproduction looks like:

irb(main):001:0> require 'rmagick'
=> true
irb(main):002:0> image = Magick::Image.read('C:\somewhere\in.png').first
=> #<Magick::Image:0x5c7933ad @image=#<Java::Magick4j::MagickImage:0x57bc27f5>>
irb(main):003:0> image.write('C:\somewhere\out1.png')
=> #<Magick::Image:0x5c7933ad @image=#<Java::Magick4j::MagickImage:0x57bc27f5>>

At this point the file C:\somewhere\out1.png gets generated and it's empty.

What is interesting is that this works correctly:

irb(main):004:0> File.open('C:\somewhere\out2.png', 'wb') { |file| file.write(image.to_blob) }
=> 1654

Both of these end up calling MagickImage::writeImage. So I am assuming that the problem is somewhere in MagickImage::write. I don't have a fix for this, but the obvious workaround is to monkeypatch the write method:

module Magick
  class Image
    def write(file, &add)
      File.open(file, 'wb') { |file| file.write(to_blob) }
      self
    end
  end
end

... still a proper fix would be welcome.

Serabe commented 6 years ago

This project is unmaintained, though PRs are welcome.

Serabe commented 6 years ago

Quite likely, the problem is here https://github.com/Serabe/RMagick4J/blob/master/Magick4J/src/magick4j/MagickImage.java#L988-L995

Cannot test in a Windows machine.

The thing is there is a behaviour for settings filetype with a prefix of type jpeg:filename, so it is taking C as a filetype.

A fix is not trivial.

joankaradimov commented 6 years ago

This project is unmaintained, though PRs are welcome.

Thanks for taking the time to answer even though this is no longer maintained.

Quite likely, the problem is here

Yes, I think I see the problem.

I won't have the time now, but I am definitely interested in writing the fix and doing a PR. Maybe you can keep the issue open for now.