Open dieudv opened 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)
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.
Do you have any long term plans for this? any todo list?
I don't have any defined plans yet. There's a few options I might consider:
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.
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 .
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
.
Since the set_options
method doesn't work and isn't very Pythonic, I guess the .save
should be the only officially supported method?
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()
.
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.
I only can change ImageWriter.dpi but font size not correct (code128 & dpi = 100) And set_options has no effect