WhyNotHugo / python-barcode

㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.
http://python-barcode.rtfd.io/
MIT License
576 stars 124 forks source link

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

Open dieudv opened 6 years ago

dieudv commented 6 years ago

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

Sharlock93 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

WhyNotHugo commented 6 years ago

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

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 commented 6 years ago

Ah exams, good luck dude. the problem is that there is a call when things get rendered that pass the default available options, I figured that out just by quickly using a bunch of prints, I will look into it further and report it to you.

On Thu, Nov 29, 2018 at 9:10 PM Hugo Osvaldo Barrera < notifications@github.com> wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/WhyNotHugo/python-barcode/issues/17#issuecomment-442935779, or mute the thread https://github.com/notifications/unsubscribe-auth/ADUdt_E_vCzTudx0vMTIHmjfYmrThlb_ks5u0CMVgaJpZM4YLECu .

Sharlock93 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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.