public static function strToBin($imageString): string
    {
        $cleanedString = str_replace(' ', '+', preg_replace('#^data:image/[^;]+;base64,#', '', $imageString));
        $result = base64_decode($cleanedString, true);

        if (!$result) {
            $result = $imageString;
        }

        return $result;
    }
public static function strToBin($imageString): string
    {
        $cleanedString = str_replace(' ', '+', preg_replace('#^data:image/[^;]+;base64,#', '', $imageString));
        $result = base64_decode($cleanedString, true);

        if (!$result) {
            $result = $imageString;
        }

        return $result;
    }
public static function strToBin ( $ imageString ) : string { $ cleanedString = str_replace ( ' ' , '+' , preg_replace ( '#^data:image/[^;]+;base64,#' , '' , $ imageString ) ) ; $ result = base64_decode ( $ cleanedString , true ) ; if ( ! $ result ) { $ result = $ imageString ; } return $ result ; }
Convert string to binary data

@param $imageString
@return string
Convert string to binary data