@@ -32,8 +32,6 @@ class ImageMagickHandler extends BaseHandler
3232 protected $ resource ;
3333
3434 /**
35- * Constructor.
36- *
3735 * @param Images $config
3836 *
3937 * @throws ImageException
@@ -45,6 +43,22 @@ public function __construct($config = null)
4543 if (! (extension_loaded ('imagick ' ) || class_exists (Imagick::class))) {
4644 throw ImageException::forMissingExtension ('IMAGICK ' ); // @codeCoverageIgnore
4745 }
46+
47+ $ cmd = $ this ->config ->libraryPath ;
48+
49+ if ($ cmd === '' ) {
50+ throw ImageException::forInvalidImageLibraryPath ($ cmd );
51+ }
52+
53+ if (preg_match ('/convert$/i ' , $ cmd ) !== 1 ) {
54+ $ cmd = rtrim ($ cmd , '\/ ' ) . '/convert ' ;
55+
56+ $ this ->config ->libraryPath = $ cmd ;
57+ }
58+
59+ if (! is_file ($ cmd )) {
60+ throw ImageException::forInvalidImageLibraryPath ($ cmd );
61+ }
4862 }
4963
5064 /**
@@ -184,19 +198,10 @@ public function getVersion(): string
184198 */
185199 protected function process (string $ action , int $ quality = 100 ): array
186200 {
187- // Do we have a vaild library path?
188- if (empty ($ this ->config ->libraryPath )) {
189- throw ImageException::forInvalidImageLibraryPath ($ this ->config ->libraryPath );
190- }
191-
192201 if ($ action !== '-version ' ) {
193202 $ this ->supportedFormatCheck ();
194203 }
195204
196- if (! preg_match ('/convert$/i ' , $ this ->config ->libraryPath )) {
197- $ this ->config ->libraryPath = rtrim ($ this ->config ->libraryPath , '/ ' ) . '/convert ' ;
198- }
199-
200205 $ cmd = $ this ->config ->libraryPath ;
201206 $ cmd .= $ action === '-version ' ? ' ' . $ action : ' -quality ' . $ quality . ' ' . $ action ;
202207
0 commit comments