Deprecated Functionality: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated

After updating imagekit-magento plugin to 1.4.1 I get an error in Magento Admin > Catalog > Products

eprecated in /var/www/html/vendor/imagekit/imagekit-magento/Plugin/Helper/Image.php on line 65 in /var/www/html/vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8192, 'ltrim(): Passin...', '/var/www/html/v...', 65)
#1 /var/www/html/vendor/imagekit/imagekit-magento/Plugin/Helper/Image.php(65): ltrim(NULL, '/')
#2 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): ImageKit\ImageKitMagento\Plugin\Helper\Image->aroundGetUrl(Object(Magento\Catalog\Helper\Image\Interceptor), Object(Closure))
#3 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Helper\Image\Interceptor->Magento\Framework\Interception\{closure}()
#4 /var/www/html/generated/code/Magento/Catalog/Helper/Image/Interceptor.php(50): Magento\Catalog\Helper\Image\Interceptor->___callPlugins('getUrl', Array, NULL)
#5 /var/www/html/vendor/magento/module-catalog/Ui/Component/Listing/Columns/Thumbnail.php(67): Magento\Catalog\Helper\Image\Interceptor->getUrl()
#6 /var/www/html/vendor/magento/framework/View/Element/UiComponent/Context.php(403): Magento\Catalog\Ui\Component\Listing\Columns\Thumbnail->prepareDataSource(Array)
#7 /var/www/html/vendor/magento/framework/View/Element/UiComponent/Context.php(400): Magento\Framework\View\Element\UiComponent\Context->prepareDataSource(Array, Object(Magento\Catalog\Ui\Component\Listing\Columns\Thumbnail))
#8 /var/www/html/vendor/magento/framework/View/Element/UiComponent/Context.php(400): Magento\Framework\View\Element\UiComponent\Context->prepareDataSource(Array, Object(Magento\Catalog\Ui\Component\Listing\Columns\Interceptor))
#9 /var/www/html/vendor/magento/framework/View/Element/UiComponent/Context.php(251): Magento\Framework\View\Element\UiComponent\Context->prepareDataSource(Array, Object(Magento\Ui\Component\Listing))
#10 /var/www/html/vendor/magento/framework/View/Element/UiComponent/ContentType/Json.php(69): Magento\Framework\View\Element\UiComponent\Context->getDataSourceData(Object(Magento\Ui\Component\Listing))
#11 /var/www/html/vendor/magento/module-ui/Component/AbstractComponent.php(158): Magento\Framework\View\Element\UiComponent\ContentType\Json->render(Object(Magento\Ui\Component\Listing), 'templates/listi...')
#12 /var/www/html/vendor/magento/module-ui/Component/Listing.php(77): Magento\Ui\Component\AbstractComponent->render()
#13 /var/www/html/vendor/magento/module-ui/Controller/Adminhtml/Index/Render.php(91): Magento\Ui\Component\Listing->render()
#14 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Ui\Controller\Adminhtml\Index\Render->execute()
#15 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->___callParent('execute', Array)
#16 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->Magento\Framework\Interception\{closure}()
#17 /var/www/html/generated/code/Magento/Ui/Controller/Adminhtml/Index/Render/Interceptor.php(23): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->___callPlugins('execute', Array, Array)
#18 /var/www/html/vendor/magento/framework/App/Action/Action.php(111): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->execute()
#19 /var/www/html/vendor/magento/module-backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#20 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#21 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->___callParent('dispatch', Array)
#22 /var/www/html/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(145): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#23 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#24 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#25 /var/www/html/generated/code/Magento/Ui/Controller/Adminhtml/Index/Render/Interceptor.php(32): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->___callPlugins('dispatch', Array, Array)
#26 /var/www/html/vendor/magento/framework/App/FrontController.php(245): Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#27 /var/www/html/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse(Object(Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor), Object(Magento\Framework\App\Request\Http))
#28 /var/www/html/vendor/magento/framework/App/FrontController.php(146): Magento\Framework\App\FrontController->processRequest(Object(Magento\Framework\App\Request\Http), Object(Magento\Ui\Controller\Adminhtml\Index\Render\Interceptor))
#29 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#30 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#31 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#32 /var/www/html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#33 /var/www/html/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#34 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Http->launch()
#35 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\Http\Interceptor->___callParent('launch', Array)
#36 /var/www/html/vendor/magento/module-application-performance-monitor/Plugin/ApplicationPerformanceMonitor.php(38): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#37 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\ApplicationPerformanceMonitor\Plugin\ApplicationPerformanceMonitor->aroundLaunch(Object(Magento\Framework\App\Http\Interceptor), Object(Closure))
#38 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#39 /var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http\Interceptor->___callPlugins('launch', Array, NULL)
#40 /var/www/html/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#41 /var/www/html/pub/index.php(30): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#42 {main} {"exception":"[object] (Exception(code: 0): Deprecated Functionality: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/vendor/imagekit/imagekit-magento/Plugin/Helper/Image.php on line 65 at /var/www/html/vendor/magento/framework/App/ErrorHandler.php:61)"} []

To solve this issue I have created a patch file for Plugin/Helper/Image.php


--- a/Plugin/Helper/Image.php
+++ b/Plugin/Helper/Image.php
@@ -62,6 +62,10 @@ class Image

         $imagePath = $this->imageFile ?: $this->product->getData($helper->getType());
+        if ($imagePath === null) {
+            return $originalMethod();
+        }
+
         $imagePath = ltrim($imagePath, '/');
         $imagePath = preg_replace('#^media/#', '', $imagePath);
         $imagePath = preg_replace('#^catalog/product/#', '', $imagePath);