Bug Summary
On windows, opening a site shell results in a bunch of "Unable to load dynamic library ‘php_imagick.dll’ " warnings to be printed. This happens both with the “command prompt” and “git bash” terminal setting.
See also:
- PHP 7.4.1 and Windows 10 lead to WP-CLI: Warning: PHP Startup: Unable to load dynamic library 'php_imagick.dll'
- PHP Startup: Unable to load dynamic library 'php_imagick.dll'
- WP-CLI warnings with PHP 7.4.1 on Windows 10
- PHP imagick issue on Windows 10
Steps to reproduce
Simply open a site shell on Windows and observe the warnings.
This happens both with the “command prompt” and “git bash” terminal setting.
Environment Info
Describe your environment.
For me this happens on Windows 10 using Local 6.2.0+5679 with at least PHP 7.4.1
I have not tested other PHP versions but due to the nature of how ImageMagick and the imagick PHP extension are included in the package I have no doubt those are going to suffer from similar if not identical bugs.
Other environments described in the provided community threads above.
How to fix
There’s a couple of things in %APPDATA%\Local\lightning-services\php-7.4.1+16\lib\PhpService.js that can be improved regarding how ImageMagick paths are handled. Complete file attached. Patch for quick review below.
PhpService.zip (2.5 KB)
--- <unnamed>
+++ <unnamed>
@@ -87,13 +87,15 @@
};
}
get siteShellStartupBat() {
- return `\nSET PATH=${path_1.default.join(this.$PATH, 'ImageMagick')};%PATH%\n`;
+ return `\nSET PATH=${path_1.default.join(this.$PATH, 'ImageMagick', 'bin')};%PATH%\n`;
}
get siteShellStartupPOSIX() {
let shellStartup = `\nexport MAGICK_CODER_MODULE_PATH="${this.imageMagickCodersDir}"\n`;
switch (os_1.default.platform()) {
case 'linux':
shellStartup += `\nexport LD_LIBRARY_PATH="${path_1.default.join(__dirname, '../bin', 'linux', 'shared-libs')}"\n`;
+ case 'win32':
+ shellStartup += `\nexport PATH="${this.toPOSIX(this.imageMagickBinDir)}:$PATH\"n`;
}
return shellStartup;
}
@@ -115,13 +117,38 @@
});
}
/**
+ * This probably has an importable helper somewhere but no idea how to import it here
+ */
+ toPOSIX(t) {
+ let e = t.replace(/\\/g, "/"),
+ r = !1;
+ if ("win32" === os_1.default.platform()) {
+ 0 === t.indexOf("\\\\") && (r = !0), 1 === t.indexOf(":") && (e = e.replace(":", ""));
+ const a = e.split("/").filter((t) => t);
+ 1 === a[0].length && (a[0] = a[0].toLowerCase()), (e = "/" + a.join("/")), r && (e = "/" + e);
+ }
+ return e;
+ }
+ /**
* Coders directory required by ImageMagick
*/
+ get imageMagickBinDir() {
+ if (os_1.default.platform() === 'win32' && !Local.isWindows32Bit()) {
+ return path_1.default.join(__dirname, '../bin', 'win64', 'ImageMagick', 'bin');
+ }
+ return path_1.default.join(__dirname, '../bin', os_1.default.platform(), 'ImageMagick', 'bin');
+ }
get imageMagickCodersDir() {
+ if (os_1.default.platform() === 'win32' && !Local.isWindows32Bit()) {
+ return path_1.default.join(__dirname, '../bin', 'win64', 'ImageMagick', 'modules-Q16', 'coders');
+ }
return path_1.default.join(__dirname, '../bin', os_1.default.platform(), 'ImageMagick', 'modules-Q16', 'coders');
}
get ghostscriptLib() {
// GS_LIB env variable in fpm www config
+ if (os_1.default.platform() === 'win32' && !Local.isWindows32Bit()) {
+ return path_1.default.join(__dirname, '../bin', 'win64', 'ghostscript', 'Resource', 'Init');
+ }
return path_1.default.join(__dirname, '../bin', os_1.default.platform(), 'ghostscript', 'Resource', 'Init');
}
get lightningServicePlatform() {