-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d38a19
commit ad437f2
Showing
5 changed files
with
189 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
# Zbar | ||
|
||
**TODO: Add description** | ||
Scan one or more barcodes from a JPEG image. | ||
|
||
The API for this library is very simple: | ||
|
||
```elixir | ||
iex> File.read!("QR_REF1.jpg") |> Zbar.scan() | ||
%Zbar.Symbol{ | ||
data: "REF1", | ||
points: [{40, 40}, {40, 250}, {250, 250}, {250, 40}], | ||
quality: 1, | ||
type: "QR-Code" | ||
} | ||
``` | ||
|
||
More detailed API documentation can be found at | ||
[https://hexdocs.pm/zbar](https://hexdocs.pm/zbar). | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `zbar` to your list of dependencies in `mix.exs`: | ||
This library can be installed by adding `zbar` to your list of dependencies in | ||
`mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[{:zbar, "~> 0.1.0"}] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at [https://hexdocs.pm/zbar](https://hexdocs.pm/zbar). | ||
You will also need to have `zbar` and `libjpeg` installed in order to compile | ||
the required native code. On OSX with Homebrew, this is as simple as: | ||
|
||
```bash | ||
$ brew install zbar libjpeg | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,56 @@ | ||
defmodule Zbar.Symbol do | ||
alias __MODULE__ | ||
|
||
defstruct [:type, :quality, :points, :data] | ||
|
||
def parse(string) do | ||
string | ||
|> String.split(" ") | ||
|> Enum.reduce(%Symbol{}, fn item, acc -> | ||
[key, value] = String.split(item, ":", parts: 2) | ||
case key do | ||
"type" -> | ||
%Symbol{acc | type: value} | ||
|
||
"quality" -> | ||
%Symbol{acc | quality: String.to_integer(value)} | ||
|
||
"points" -> | ||
%Symbol{acc | points: parse_points(value)} | ||
|
||
"data" -> | ||
%Symbol{acc | data: Base.decode64!(value)} | ||
end | ||
end) | ||
end | ||
|
||
defp parse_points(string) do | ||
string | ||
|> String.split(";") | ||
|> Enum.map(& parse_point/1) | ||
end | ||
|
||
defp parse_point(string) do | ||
[x, y] = String.split(string, ",", parts: 2) | ||
{String.to_integer(x), String.to_integer(y)} | ||
end | ||
@moduledoc """ | ||
The `Zbar.Symbol` struct represents a barcode that has been detected by `zbar`. | ||
It has the following fields: | ||
* `type`: The type of barcode that has been detected, as a string. Possible | ||
values are listed in `t:type_enum/0` | ||
* `quality`: An integer metric representing barcode scan confidence. | ||
Larger values are better than smaller values, but only the ordered | ||
relationship between two values is meaningful. The values themselves | ||
are not defined and may change in future versions of the library. | ||
* `points`: The list of coordinates (encoded as `{x, y}` tuples) where a | ||
barcode was located within the source image. | ||
The structure of the points depends on the type of barcode being scanned. | ||
For example, for the `QR-Code` type, the points represent the bounding | ||
rectangle, with the first point indicating the top-left positioning pattern | ||
of the QR-Code if it had not been rotated. | ||
* `data`: The actual barcode data, as a binary string. | ||
Note that this is a string that may contain arbitrary binary data, | ||
including non-printable characters. | ||
""" | ||
|
||
defstruct type: :UNKNOWN, quality: 0, points: [], data: nil | ||
|
||
@type type_enum :: | ||
:CODE_39 | ||
| :CODE_128 | ||
| :EAN_8 | ||
| :EAN_13 | ||
| :I2_5 | ||
| :ISBN_10 | ||
| :ISBN_13 | ||
| :PDF417 | ||
| :QR_Code | ||
| :UPC_A | ||
| :UPC_E | ||
| :UNKNOWN | ||
|
||
@type point :: {non_neg_integer(), non_neg_integer()} | ||
|
||
@typedoc @moduledoc | ||
@type t :: %__MODULE__{ | ||
type: type_enum(), | ||
quality: non_neg_integer(), | ||
points: [point()], | ||
data: binary() | ||
} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
%{"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [], [], "hexpm"}} | ||
%{"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [], [], "hexpm"}, | ||
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [], [], "hexpm"}, | ||
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [], [], "hexpm"}, | ||
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}} |