Issue Bug Closed

#24931Quoting of path and filename in ImageMagick/GraphicsMagick not working on Windows + PHP5.2

Jörg Wagner 02/02/11, 13:38 updated 02/22/11, 23:24

Description

Quoting of the path and filename of the ImageMagick/GraphicsMagick executable has been introduced with 4.4.5. Here is an example:

4.4.4:
C:\Programme\GraphicsMagick-1.3.7-Q8/gm.exe convert -geometry 50x50! "uploads/pics/myimage.gif[0]" "typo3temp/pics/f58c0b5193.gif"
4.4.5:
"C:/Programme/GraphicsMagick-1.3.7-Q8/gm.exe" convert +profile '*' -geometry 50x50! "uploads/pics/myimage.gif"[0] "typo3temp/pics/f58c0b5193.gif"

Both of these commands will work, if executed directly on the Windows command line. But the 4.4.5 version will fail when executed through the PHP exec() command on Windows with PHP versions below 5.3.
For the exec() command of PHP >=5.3 both commands will work nicely.

Explanation for PHP < 5.3:
The quoting of the IM/GM executable path and filename in the complete command line requires the whole string to be quoted a second time, to make it work with exec() on Windows. Details can be found in the posting of “luko post cz”, 30-Jan-2008 02:15, on http://php.net/manual/en/ref.exec.php

The working version for 4.4.5 must look like this:

""C:/Programme/GraphicsMagick-1.3.7-Q8/gm.exe" convert +profile '*' -geometry 50x50! "uploads/pics/myimage.gif"[0] "typo3temp/pics/f58c0b5193.gif""

Explanation for PHP >=5.3:
The PHP 5.3.0 change log (http://php.net/ChangeLog-5.php) contains a hint that the exec() behavior has been changed:

Version 5.3.0
30-June-2009
...
Fixed exec() on Windows to not eat the first and last double quotes. (Scott)

Bottom line
Quoting twice is the way to go on Windows, but is needed and working only for PHP versions below 5.3 on Windows. For PHP >=5.3 this is NOT needed and actually results in an error!

The attached patches for TYPO3 4.4.5 and TYPO3 4.5.0 will correct the problem with all PHP 5 versions on Windows.

(issue imported from #M17447)

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.