Problem/Motivation
Experimented in #3414412: [experimental] remove locale swapping.
Currently the module performs a lot of locale swapping to escape command line parameters. Symfony Process manages this seamlessly.
Proposed resolution
Switch to use Symfony Process with an array of parameters (natively) instead of escaping arguments and composing a stringed command line.
API changes
The escaping of the command line parameters is no longer executed by the module. Symfony Process is now invoked with an array of command line parameters, and each one is escaped by Symfony directly. This makes the escaping methods no longer relevant, and requires some adjustments to the parameters building and the command execution parameters.
The following code is deprecated:
src/ImagemagickExecArguments::add(), for adding strings. Arrays should be added instead.src/ImagemagickExecArguments::escape(), no replacement.src/ImagemagickExecManager::PERCENTAGE_REPLACE, no replacement.src/ImagemagickExecManager::toString(), Use ::toArray() for command execution or ::toDebugString() to get a string representing the command parameters for debug purposes.src/ImagemagickExecManager::runOsShell(), use ::runProcess() instead.src/ImagemagickExecManager::escapeShellArg(), no replacement.src/Plugin/ImageToolkit/Operation/imagemagick/ImagemagickImageToolkitOperationBase::addArgument(), use ::addArguments() instead.src/Plugin/ImageToolkit/Operation/imagemagick/ImagemagickImageToolkitOperationBase::escapeArgument(), no replacement.
Modules that provide image toolkit operation plugins need to adjust their calls to building arguments, from adding strings to adding array of strings, each one being an individual command line parameter for the process execution.
Example:
Before:
$this->addArgument(sprintf('-crop %dx%d%+d%+d +repage', $arguments['width'], $arguments['height'], $arguments['x'], $arguments['y']));
After:
$this->addArguments([
'-crop',
sprintf('%dx%d%+d%+d', $arguments['width'], $arguments['height'], $arguments['x'], $arguments['y']),
'+repage',
]);
Issue fork imagemagick-3414601
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3414601-II
changes, plain diff MR !32
- 3414601-switch-command-line
changes, plain diff MR !31
Comments
Comment #3
mondrakeComment #5
mondraketo be ported to 4.0.x
Comment #9
mondrakeSome tweaks needed.
Comment #14
mondrakeComment #15
mondrakeComment #16
mondrakeComment #17
mondrake