Documentation ¶
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func GetData ¶
GetData generates a byte slice containing the data from the given slice of QRChunk pointers.
It takes a slice of pointers to QRChunk objects as a parameter. If the slice is empty, it returns nil. Otherwise, it creates a new byte slice with an initial capacity equal to the estimated data size of the first chunk. It then iterates over each chunk in the slice and appends its data to the data slice. Finally, it returns the generated data slice.
Parameters: - chunks: a slice of pointers to QRChunk objects.
Returns:
- []byte: a byte slice containing the data from the QRChunk pointers, or nil if the input slice is empty.
func NewImageWriter ¶
NewImageWriter creates a new instance of the imgWriter struct and returns it as a qrcode.Writer.
The function takes two parameters:
- callback: a function that takes an image.Image as input and does not return anything.
- opt: a pointer to an Option struct.
The function returns a qrcode.Writer.
Types ¶
type QRChunk ¶
type QRChunk struct {
// contains filtered or unexported fields
}
func CreateChunks ¶
CreateChunks generates a slice of QRChunk pointers based on the given data and chunk size.
Parameters: - data: a byte slice containing the data to be split into chunks. - chunkSize: an unsigned 16-bit integer specifying the size of each chunk.
Returns: - []*QRChunk: a slice of pointers to QRChunk objects.
func NewChunk ¶
NewChunk creates a new QRChunk from the given byte slice.
The function takes a byte slice as input and extracts the necessary information to create a new QRChunk. It first extracts the values for nr and tot from the first two bytes of the input data. Then, it reads the chunk size from the next two bytes and checks if it is a valid chunk size using the isValidChunkSize function. If the chunk size is invalid, the function returns nil. Otherwise, it creates a new QRChunk with the extracted values and the remaining data.
Parameters:
- data: a byte slice containing the data for the QRChunk.
Returns:
- *QRChunk: a pointer to the newly created QRChunk, or nil if the chunk size is invalid.
func NewChunkFromImage ¶
NewChunkFromImage decodes an image into a QRChunk.
It takes an image.Image as a parameter and attempts to decode it into a QRChunk. It first creates a BinaryBitmap from the image using the gozxing.NewBinaryBitmapFromImage function. Then it creates a QRCodeReader and uses it to decode the BinaryBitmap into a QRCodeData object. The QRCodeData object contains the text of the QR code, which is then decoded from base64 to bytes using the base64.StdEncoding.DecodeString function. Finally, it creates a new QRChunk using the NewChunk function and returns it along with any error that occurred during the decoding process. If the decoded chunk is invalid, it returns an error.
Parameters: - img: an image.Image to be decoded into a QRChunk.
Returns:
- *QRChunk: the decoded QRChunk.
- error: an error if there was an issue decoding the image or if the decoded chunk is invalid.
func (QRChunk) QRCode ¶
QRCode generates a QR code image based on the data of the QRChunk.
It takes an integer parameter `blockSize` which represents the size of the blocks in the QR code. The function returns two values: `img` of type `image.Image` which is the generated QR code image, and `err` of type `error` which indicates any error that occurred during the generation process.
If the `blockSize` parameter is less than 1, the function returns an error indicating an invalid block size. The function then creates a new QR code using the `qrcode.New` function, passing the base64-encoded data of the QRChunk. If there is an error creating the QR code, the function returns the error. The function creates a new `ImageWriter` with a callback function that assigns the generated image to the `img` variable. The `ImageWriter` is configured with the `Padding` and `BlockSize` options set to the `blockSize` parameter. The function saves the QR code using the `qr.Save` method, passing the `ImageWriter` as the writer. If there is an error saving the QR code, the function returns the error. The function returns the generated image and any error that occurred during the process.