yeqown / go-qrcode

To help gophers generate QR Codes with customized styles, such as color, block size, block shape, and icon.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A few questions

samstride opened this issue · comments

commented

Hi,

Thank you for making this library available.

I have a few questions:

  • Why do some QR codes generated have no borders to the bottom and right? Example -> this one
  • Can you provide an example of SaveTo that can save to a PNG file?
  • Do you plan to support HEIF? i.e. SaveTo HEIF

I am trying to use SaveTo to write to a buffer first because my container is locked down and I am POSTing the data to another URL.

Example code:

       qrc, _ := qrcode.New("https://www.google.com")
	
       // save file
	var file bytes.Buffer
        _ = qrc.SaveTo(&file)

	var payload bytes.Buffer
	writer := multipart.NewWriter(&payload)

        part, _ := writer.CreateFormFile("file", "google")

	fileBytes, _ := ioutil.ReadAll(&file)

	_, _ = part.Write(fileBytes)
	writer.Close()

	request, _ := http.NewRequest("POST", "<another_service>", &payload)

	request.Header.Add("Content-Type", writer.FormDataContentType())
	client := &http.Client{}
	response, _ := client.Do(request)
	defer response.Body.Close()

The file that is produced by SaveTo is always of type image/jpeg.

Would be nice to support type of image/png and image/heif.

Q1: I will check about this, maybe a bug ~
Q2: It hasn't a config to specify the output format, I will support this soon
Q3: Writer is written by JPEG formatted bytes, so you got the result

A new feature branch named feature/support-output-file-format will be open, I will let you know as soon as I finish this.

Finally, I have no idea about the HEIF format, if you have any good Documents about this, that would be nice for supporting this.

commented

@yeqown , thanks.

I think if you google heif you will get some info. Most iPhones default to using this format now since quality/size ratio is better.

@samstride

All changes are in feature/support-output-file-format:

  1. Q1 is a bug and has been fixed.
  2. Q2 and Q3,I add two API to provide the function of specifying file format:
    2.1 WithBuiltinImageEncoder to specify JPEG and PNG format
    2.2 WithCustomImageEncoder to use custom image format, such as HEIF or others

if you want to implement the HEIF format, it maybe looks like:

type heifEncoder struct{}

func (e heifEncoder) Encode(w io.Writer, img image.Image) error {
   // ignore implementation
}

qrcode.New(text, WithCustomImageEncoder(new(heifEncoder)))
commented

Thanks. Do you plan to do a release? That way I can simply update my go.mod and the changes will be pulled down.

PS: I have sent you an email on your gmail.