Sybio / ImageWorkshop

ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library
http://phpimageworkshop.com/
Other
862 stars 189 forks source link

Fix in convertHexToRGB method #140

Closed guisaldanha closed 2 years ago

guisaldanha commented 2 years ago
Q A
Bug report? yes
Feature request? no
Usage question? no
PHP version used 8.1

Fix in convertHexToRGB method. PHP 8.1 does not allow the input string to be null. What causes: <b>Deprecated</b>: substr(): Passing null to parameter #1 ($string) of type string is deprecated in <b>\vendor\sybio\image-workshop\src\Core\ImageWorkshopLib.php</b> on line <b>80</b><br />

Suggested fix

On lines 80, 81 and 82 of the src/Core/ImageWorkshopLib.php file, change the convertHexToRGB method by adding ?? '', as below:

public static function convertHexToRGB($hex)
     {
         return array(
             'R' => (int) base_convert(substr($hex ?? '', 0, 2), 16, 10),
             'G' => (int) base_convert(substr($hex ?? '', 2, 2), 16, 10),
             'B' => (int) base_convert(substr($hex ?? '', 4, 2), 16, 10),
         );
     }
jdecool commented 2 years ago

Hey @guisaldanha,

Thanks for reporting this bug.

Can you make a PR to fix it ?

guisaldanha commented 2 years ago

It was fixed, thank you