Skip to content

fix: change convert.exe syntax to avoid clash in Windows - #2951

Closed
coz-eduardo-hernandez wants to merge 2 commits into
synfig:masterfrom
coz-eduardo-hernandez:imagemagick7
Closed

coz-eduardo-hernandez wants to merge 2 commits into
synfig:masterfrom
coz-eduardo-hernandez:imagemagick7

Conversation

@coz-eduardo-hernandez

@coz-eduardo-hernandez coz-eduardo-hernandez commented Dec 18, 2022 •

Copy link
Copy Markdown
Contributor

On Windows (I built with CMake) for some weird reason calling ImageMagick's convert calls Windows/System32/convert.exe . It's odd because my Path env var seems to list the mingw64 directory first, but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per https://imagemagick.org/script/command-line-tools.php

The problem is widely known as per https://stackoverflow.com/questions/3060205/error-invalid-parameter-fom-imagemagick-convert-on-windows , I was getting the same 'Invalid Parameter' error

The patch uses 'magick convert' (legacy syntax), instead of 'magick' for compatibility with ImageMagick 6, since many distros don't have official packages for ImageMagick 7, despite the release being over 5 years old:

The reason is that v7's syntax is not fully compatible with v6 but it our syntax seems safe

TL;DR:
Instead of using ImageMagick with 'convert' use 'magick convert' since Win has another 'convert' program

@ice0

ice0 commented Dec 19, 2022

Copy link
Copy Markdown
Collaborator

It's odd because my Path env var seems to list the mingw64 directory first,

Can you describe your build environment/process?
I also experienced this issue before, but I don't remember how to reproduce it.

but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per

Yes, I was also thinking about the same solution, but we can't use it because some OSes (like Debian 10) are still using ImageMagick 6, so they don't have the magick binary.

https://pkgs.org/search/?q=imagemagick

@coz-eduardo-hernandez

Copy link
Copy Markdown
Contributor Author

Can you describe your build environment/process?

  • I'm using a Windows 10 64-bit Home ( version 21H2 ), on an x64-based processor
  • I'm compiling under MSYS2 MINGW64 ( version 20221028 )
  • I'm building with CMake with type Release since Debug exports too many symbols
  • printing 'getenv( "Path" )' from RunPipeWin32::open() outputs
    C:\Users\coz\Desktop\Agames\tools\msys64\home\coz\synfig\cmake-build-msys\output\Release\bin;C:\Users\coz\Desktop\Agames\tools\msys64\mingw64\bin;C:\Users\coz\Desktop\Agames\tools\msys64\usr\local\bin;C:\Users\coz\Desktop\Agames\tools\msys64\usr\bin;C:\Users\coz\Desktop\Agames\tools\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\coz\Desktop\Agames\tools\msys64\usr\bin\site_perl;C:\Users\coz\Desktop\Agames\tools\msys64\usr\bin\vendor_perl;C:\Users\coz\Desktop\Agames\tools\msys64\usr\bin\core_perl
  • '$whereis convert' outputs
    convert: /mingw64/bin/convert.exe /c/Windows/System32/convert.exe

And that is it, I'm not sure if there's anything else that can be relevant

Yes, I was also thinking about the same solution, but we can't use it because some OSes (like Debian 10) are still using ImageMagick 6, so they don't have the magick binary.

Aaaah, I thought the 'legacy' syntax allowed near-identical use with v6

@coz-eduardo-hernandez

Copy link
Copy Markdown
Contributor Author

Well, I found the reason of the issue
As per https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa regardless of what you have in PATH dearest windows looks in the 32-bit system directory first when running CreateProcessW in os.cpp .

The only sensible solution then is to pass the full path to the convert utility

@ice0

ice0 commented Dec 19, 2022

Copy link
Copy Markdown
Collaborator

Well, I found the reason of the issue As per https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa regardless of what you have in PATH dearest windows looks in the 32-bit system directory first when running CreateProcessW in os.cpp .

Exactly!

The only sensible solution then is to pass the full path to the convert utility

Agree.

@BobSynfig

Copy link
Copy Markdown
Collaborator

As per https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa regardless of what you have in PATH dearest windows looks in the 32-bit system directory first when running CreateProcessW in os.cpp .
On 64bit systems, System32 contains 64bit dlls, SysWOW64 contains the 32bit ones ;)

The implied precedence for system directories is due to the risk of injection of dlls which would be loaded first from the directory of the application.
The same concern was affecting ffmpeg on Windows, you could get inspiration from the mod_ffmpeg module to deal with this.

Other fact that I noticed from 1.4.3 and 1.5.1: there is no trace of "convert" or "magick" binaries while "convert.exe" was present in 1.2.2

@coz-eduardo-hernandez

Copy link
Copy Markdown
Contributor Author

mod_ffmpeg works by relying on the packager; it assumes ffmpeg.exe will always be in the same directory as synfig.exe, but that fails on the CygWin / MinGW environment

I could implement a fix for imagemagick (traverse PATH looking for convert) but given the inconsistencies with other external dependencies like ffmpeg it feels like a hack. Instead I'm going to work on Synfig by starting from the base. Since that needs majority agreement, I made a new post in the forums. I hope that Konstantin can also chime in too for those general decisions

@rodolforg

Copy link
Copy Markdown
Contributor

Other fact that I noticed from 1.4.3 and 1.5.1: there is no trace of "convert" or "magick" binaries while "convert.exe" was present in 1.2.2

@morevnaproject

@rodolforg

Copy link
Copy Markdown
Contributor

@coz-eduardo-hernandez please edit commit messages and PR title to use Conventional Commits

@coz-eduardo-hernandez coz-eduardo-hernandez changed the title Change ImageMagick command syntax to avoid clash with Window's convert.exe refactor: change convert.exe syntax to avoid clash in Windows Dec 26, 2022
@coz-eduardo-hernandez coz-eduardo-hernandez changed the title refactor: change convert.exe syntax to avoid clash in Windows fix: change convert.exe syntax to avoid clash in Windows Dec 26, 2022
@coz-eduardo-hernandez

Copy link
Copy Markdown
Contributor Author

Since my 'fix' is not convenient at this time, I have no problem if the pull request is closed; an issue could be created for the convert.exe clash instead if desired. That being said, if it would be better to leave this pull request open as a reminder that the clash still happens, that's also fine with me. I'm not really sure what would fit the devs workflow best.

@rodolforg

Copy link
Copy Markdown
Contributor

but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per

Yes, I was also thinking about the same solution, but we can't use it because some OSes (like Debian 10) are still using ImageMagick 6, so they don't have the magick binary.

What about test "magick" first? If it doesn't exist, we try traditional "convert" then.

rodolforg added a commit to rodolforg/synfig that referenced this pull request Dec 25, 2023
On Windows (I built with CMake) for some weird reason calling ImageMagick's convert calls Windows/System32/convert.exe . It's odd because my Path env var seems to list the mingw64 directory first, but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per https://imagemagick.org/script/command-line-tools.php

The problem is widely known as per https://stackoverflow.com/questions/3060205/error-invalid-parameter-fom-imagemagick-convert-on-windows , I was getting the same 'Invalid Parameter' error

The patch uses 'magick convert' (legacy syntax), instead of 'magick' for compatibility with ImageMagick 6, since many distros don't have official packages for ImageMagick 7, despite the release being over 5 years old:

    https://packages.debian.org/search?searchon=sourcenames&keywords=imagemagick
    https://packages.fedoraproject.org/pkgs/ImageMagick/ImageMagick/
    https://packages.ubuntu.com/search?keywords=imagemagick

The reason is that v7's syntax is not fully compatible with v6 but it our syntax seems safe

TL;DR:
Instead of using ImageMagick with 'convert' use 'magick convert' since Win has another 'convert' program

Supersedes: synfig#2951

Co-authored-by: Eduardo Hernández <[email protected]>
@rodolforg

Copy link
Copy Markdown
Contributor

@coz-eduardo-hernandez @ice0
what do you think about this: rodolforg@d78e4f5 ?

rodolforg added a commit to rodolforg/synfig that referenced this pull request Sep 6, 2024
On Windows (I built with CMake) for some weird reason calling ImageMagick's convert calls Windows/System32/convert.exe . It's odd because my Path env var seems to list the mingw64 directory first, but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per https://imagemagick.org/script/command-line-tools.php

The problem is widely known as per https://stackoverflow.com/questions/3060205/error-invalid-parameter-fom-imagemagick-convert-on-windows , I was getting the same 'Invalid Parameter' error

The patch uses 'magick convert' (legacy syntax), instead of 'magick' for compatibility with ImageMagick 6, since many distros don't have official packages for ImageMagick 7, despite the release being over 5 years old:

    https://packages.debian.org/search?searchon=sourcenames&keywords=imagemagick
    https://packages.fedoraproject.org/pkgs/ImageMagick/ImageMagick/
    https://packages.ubuntu.com/search?keywords=imagemagick

The reason is that v7's syntax is not fully compatible with v6 but it our syntax seems safe

TL;DR:
Instead of using ImageMagick with 'convert' use 'magick convert' since Win has another 'convert' program

Supersedes: synfig#2951

Co-authored-by: Eduardo Hernández <[email protected]>
rodolforg added a commit to rodolforg/synfig that referenced this pull request Sep 6, 2024
On Windows (I built with CMake) for some weird reason calling ImageMagick's convert calls Windows/System32/convert.exe . It's odd because my Path env var seems to list the mingw64 directory first, but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per https://imagemagick.org/script/command-line-tools.php

The problem is widely known as per https://stackoverflow.com/questions/3060205/error-invalid-parameter-fom-imagemagick-convert-on-windows , I was getting the same 'Invalid Parameter' error

The patch uses 'magick convert' (legacy syntax), instead of 'magick' for compatibility with ImageMagick 6, since many distros don't have official packages for ImageMagick 7, despite the release being over 5 years old:

    https://packages.debian.org/search?searchon=sourcenames&keywords=imagemagick
    https://packages.fedoraproject.org/pkgs/ImageMagick/ImageMagick/
    https://packages.ubuntu.com/search?keywords=imagemagick

The reason is that v7's syntax is not fully compatible with v6 but it our syntax seems safe

TL;DR:
Instead of using ImageMagick with 'convert' use 'magick convert' since Win has another 'convert' program

Supersedes: synfig#2951

Co-authored-by: Eduardo Hernández <[email protected]>
ice0 pushed a commit that referenced this pull request Sep 14, 2024
On Windows (I built with CMake) for some weird reason calling ImageMagick's convert calls Windows/System32/convert.exe . It's odd because my Path env var seems to list the mingw64 directory first, but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per https://imagemagick.org/script/command-line-tools.php

The problem is widely known as per https://stackoverflow.com/questions/3060205/error-invalid-parameter-fom-imagemagick-convert-on-windows , I was getting the same 'Invalid Parameter' error

The patch uses 'magick convert' (legacy syntax), instead of 'magick' for compatibility with ImageMagick 6, since many distros don't have official packages for ImageMagick 7, despite the release being over 5 years old:

    https://packages.debian.org/search?searchon=sourcenames&keywords=imagemagick
    https://packages.fedoraproject.org/pkgs/ImageMagick/ImageMagick/
    https://packages.ubuntu.com/search?keywords=imagemagick

The reason is that v7's syntax is not fully compatible with v6 but it our syntax seems safe

TL;DR:
Instead of using ImageMagick with 'convert' use 'magick convert' since Win has another 'convert' program

Supersedes: #2951

Co-authored-by: Eduardo Hernández <[email protected]>
@ice0 ice0 added the Windows label Sep 14, 2024
@ice0

ice0 commented Sep 14, 2024

Copy link
Copy Markdown
Collaborator

Thank you guys!
Merged #3416 with Rodolfo additions.

@ice0 ice0 closed this Sep 14, 2024
mosasauridae pushed a commit to mosasauridae/synfig that referenced this pull request Sep 29, 2024
On Windows (I built with CMake) for some weird reason calling ImageMagick's convert calls Windows/System32/convert.exe . It's odd because my Path env var seems to list the mingw64 directory first, but a solution is using the 'magick' syntax, where you just call 'magick' to convert as per https://imagemagick.org/script/command-line-tools.php

The problem is widely known as per https://stackoverflow.com/questions/3060205/error-invalid-parameter-fom-imagemagick-convert-on-windows , I was getting the same 'Invalid Parameter' error

The patch uses 'magick convert' (legacy syntax), instead of 'magick' for compatibility with ImageMagick 6, since many distros don't have official packages for ImageMagick 7, despite the release being over 5 years old:

    https://packages.debian.org/search?searchon=sourcenames&keywords=imagemagick
    https://packages.fedoraproject.org/pkgs/ImageMagick/ImageMagick/
    https://packages.ubuntu.com/search?keywords=imagemagick

The reason is that v7's syntax is not fully compatible with v6 but it our syntax seems safe

TL;DR:
Instead of using ImageMagick with 'convert' use 'magick convert' since Win has another 'convert' program

Supersedes: synfig#2951

Co-authored-by: Eduardo Hernández <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants