Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi lines content only get first line text #21

Open
hbh112233abc opened this issue Mar 15, 2020 · 1 comment
Open

multi lines content only get first line text #21

hbh112233abc opened this issue Mar 15, 2020 · 1 comment

Comments

@hbh112233abc
Copy link

output example:

array:20 [▼
  0 => "file:///D:/www/tp6/public//images/test7.jpg (format: QR_CODE, type: ADDRESSBOOK):"
  1 => "Raw result:"
  2 => "BEGIN:VCARD"
  3 => "VERSION:3.0"
  4 => "FN:huang"
  5 => "TEL:13913942792"
  6 => "EMAIL:[email protected]"
  7 => b"ADR:ÏÃÃż¯ÃÀ"
  8 => "END:VCARD"
  9 => "Parsed result:"
  10 => "huang"
  11 => b"ÏÃÃż¯ÃÀ"
  12 => "13913942792"
  13 => "[email protected]"
  14 => "Found 4 result points."
  15 => "  Point 0: (345.5,293.5)"
  16 => "  Point 1: (345.5,104.5)"
  17 => "  Point 2: (534.5,104.5)"
  18 => "  Point 3: (521.0,280.0)"
  19 => ""
]

PHPZxingDecoder.php function createImages set $imageValue = $output[$key+2]; will only get first line text

@hbh112233abc
Copy link
Author

I suggest createImages change as below code:

private function createImages($output)
    {
        $image = array();
        $valueStartIndex = null;
        $valueEndIndex = null;
        foreach ($output as $key => $singleLine) {
            if (preg_match('/\(format/', $singleLine)) {
                $imageInfo  = $singleLine;
                $startPos   = strpos($imageInfo, "(") + 1;
                $endPos     = strpos($imageInfo, ")");
                $dataStr   = substr($imageInfo, $startPos, $endPos - $startPos);

                $dataExplode    = explode(",", $dataStr);
                $contentFormat  = explode(":", $dataExplode[0]);
                $format         = $contentFormat[1];
                $contentFormat  = explode(":", $dataExplode[1]);
                $type         = $contentFormat[1];

                $valueStartIndex = $key + 2;

                $exploded = explode(" ", $singleLine);
                $imagePath = array_shift($exploded);
            } else if (preg_match('/No barcode found/', $singleLine)) {
                $exploded = explode(" ", $singleLine);
                $imagePath = array_shift($exploded);
                $image[] = new ZxingBarNotFound($imagePath, 101, "No barcode found");
            } else if (preg_match('/Parsed result/', $singleLine)) {
                $valueEndIndex = $key;
                $valueArray = array_slice($output, $valueStartIndex, $valueEndIndex - $valueStartIndex);
                $imageValue = implode(' ', $valueArray);
                $image[] = new ZxingImage($imagePath, $imageValue, $format, $type);
            }
        }

        return $image;
    }

get imageValue from every Raw result to Parsed result, and use blank space join multi line text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant