elixir-mogrify / mogrify

Image processing in Elixir (ImageMagick command line wrapper)
MIT License
570 stars 65 forks source link

Issue overwriting image when in_place is not specified #97

Closed nathany-copia closed 3 years ago

nathany-copia commented 3 years ago

Running into an recent issue when using mogrify 0.8.0 to generate a thumbnail. It is generating the thumbnail file with the specified name, but it is also overwriting the original file with the thumbnail.

src = Path.join(folder, filename)
dest = Path.join(folder, "thumb_#{filename}")

src
|> Mogrify.open()
|> Mogrify.resize_to_limit(@thumb_size)
|> Mogrify.save(path: dest)
|> Map.get(:path)

I think this issue started when upgrading to the latest imagemagick: stable 7.0.11-13.

Wondering if you have any insights or if you can reproduce it before opening an issue over at: https://github.com/ImageMagick/ImageMagick/issues. Thanks.

yossarin commented 3 years ago

This is really an awful bug. Spent a lot of time to catch it, especially when calling Mogrify.save() concurrently

sfusato commented 3 years ago

I was going crazy until I finally figured out the issue. 30 mins ago I've updated my dev system (Manjaro) and I assume ImageMagick had an update as well.

I've downgraded ImageMagick (7.0.11.14-1 => 7.0.11.9-1) and the bug is no longer happening.

talklittle commented 3 years ago

I have reported the bug upstream: https://github.com/ImageMagick/ImageMagick/issues/3893

Thanks to commenters who included their ImageMagick version numbers.

talklittle commented 3 years ago

The upstream behavior is apparently here to stay. So we have released mogrify v0.9.0 to fix this issue by using convert and identify executables, instead of mogrify, when it is undesirable to overwrite the input file. (save/2 with in_place: true still uses mogrify.) See #99

Leaving this issue open for now for visibility.