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

How to change height, width, font size ... ? #17

Open
dieudv opened this issue Nov 2, 2018 · 9 comments
Open

How to change height, width, font size ... ? #17

dieudv opened this issue Nov 2, 2018 · 9 comments

Comments

@dieudv
Copy link

dieudv commented Nov 2, 2018

I only can change ImageWriter.dpi but font size not correct
001
(code128 & dpi = 100)
And set_options has no effect

@Sharlock93
Copy link

Sharlock93 commented Nov 23, 2018

I had problems with setting options I wanted, pass the options parameter to the save function call not set_options

options = {
    'dpi': 200,
    'module_height': 5,
    'quiet_zone': 0,
    'text_distance': 0
}


ean = barcode.get('code128')
ean('2'.zfill(4), writer = img).save('meow', options = options)

@WhyNotHugo
Copy link
Owner

Yeah, I think the API needs some simplification, having two ways of passing options is kinda pointless, and it's not the first time I've seen inconsistencies. I'll try to address it when I have a bit of time.

@Sharlock93
Copy link

Do you have any long term plans for this? any todo list?

@WhyNotHugo
Copy link
Owner

I don't have any defined plans yet. There's a few options I might consider:

  • Making options actual kwarg.
  • Removing options from either set_options or save. Not sure which one yet. It seems silly to have two ways of doing the same thing.

I've exams and other stuff going on right now, so won't be able to sit down and further address this for a while.

Finally, obviously I need to track down what's wrong that causing this specific bug and fixing that, but haven't looked at it yet.

@Sharlock93
Copy link

Sharlock93 commented Nov 29, 2018 via email

@Sharlock93
Copy link

so far what I tracked down is (and this was just a quick look):
at line 72-75 : base.py where render() is called the options argument that is passed is the one that you pass to the save() function, in the render function call you call self.writer.set_options(options) the options that are passed are the ones passed to save(), that works if you pass the options to save but if you don't pass anything to save() it will overwrite the writer options.

Also the default values of the BaseWriter are not the same with the ones in the base.py for Barcode.

@buzzlightmonth
Copy link

Since the set_options method doesn't work and isn't very Pythonic, I guess the .save should be the only officially supported method?

@lieryan
Copy link

lieryan commented Nov 26, 2020

I think we should fix *Writer.set_options() and remove save(options)/write(options) arguments.

The main reason you'd be instantiating a *Writer yourself is so that you can reuse a common *Writer options when generating multiple barcodes or to write a custom *Writer subclass. Passing options in the *Writer class is a simpler API that allows better extensibility and reusability rather than passing options in save(options).

If you just want a quick one-liner to pass all the options in one-shot, then you probably should be using the generate() shortcut method rather than .get()+save()/write(). So IMO there's no real use cases to use .get()+save()/write() that's not already better served with generate().

@WhyNotHugo
Copy link
Owner

My biggest concearn thus far has been to keep compatibility with barcode.

I think it's time to move past that, since it's proving impossible to fix some existing bugs with the existing API. too many duplicate functions, and too many ways to do the same thing.

I'm going to tag a new release with the current master, to enable addressing some of these issues (and accepting PRs). Otherwise this is just stagnating with unfixable issues in the name of backwards compatibility with a broken API.

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

No branches or pull requests

5 participants