1
0
Fork
You've already forked python-barcode
0

how to set height and width if writing to file like object? #91

Open
opened 2020年10月01日 12:28:06 +02:00 by israelcoper · 2 comments
israelcoper commented 2020年10月01日 12:28:06 +02:00 (Migrated from github.com)
Copy link

Here's my code:

def barcode_to_html(order_id, box_num):
 from barcode import Code128
 from barcode.writer import ImageWriter
 from io import BytesIO
 import base64
 file_like_object = BytesIO()
 writer = ImageWriter()
 writer.set_options({ 'module_height': 10.0 }) ## NOT WORKING
 value = f'{order_id}-{box_num}'
 Code128(value, writer=writer).write(file_like_object)
 encoded = base64.b64encode(file_like_object.getvalue()).decode("ascii")
 return f'<img src="data:image/png;base64,{encoded}" />'
Here's my code: ``` def barcode_to_html(order_id, box_num): from barcode import Code128 from barcode.writer import ImageWriter from io import BytesIO import base64 file_like_object = BytesIO() writer = ImageWriter() writer.set_options({ 'module_height': 10.0 }) ## NOT WORKING value = f'{order_id}-{box_num}' Code128(value, writer=writer).write(file_like_object) encoded = base64.b64encode(file_like_object.getvalue()).decode("ascii") return f'<img src="data:image/png;base64,{encoded}" />' ```
jhummer commented 2020年12月04日 08:57:34 +01:00 (Migrated from github.com)
Copy link

I had this issue aswell, its not totally clear in the documentation but you can pass the options to .write() instead:

Code128(value, writer=writer).write(file_like_object, options={'<option>': <value>})

I had this issue aswell, its not totally clear in the documentation but you can pass the options to .write() instead: `Code128(value, writer=writer).write(file_like_object, options={'<option>': <value>})`
avmakesh commented 2022年02月02日 11:15:32 +01:00 (Migrated from github.com)
Copy link

Use the options this way ,

 from barcode import ITF
 from io import BytesIO
 stream = BytesIO()
 options = {
 "module_width": 0.1,
 "module_height": 2,
 "quiet_zone": 0.1,
 "write_text": False,
 "text_distance": 2,
 }
 Code128(code_str, writer=writer1, narrow=1, wide=3).write(stream, options)
Use the options this way , from barcode import ITF from io import BytesIO stream = BytesIO() options = { "module_width": 0.1, "module_height": 2, "quiet_zone": 0.1, "write_text": False, "text_distance": 2, } Code128(code_str, writer=writer1, narrow=1, wide=3).write(stream, options)
Sign in to join this conversation.
No Branch/Tag specified
main
pre-commit-ci-update-config
extensibility
fix_sizes
feature/longer_guard_bar
ean-without-checksum
readme-formatting
cleaning
cleanup
srolin/master
michieldwitte/left-alignment-fix
v0.13.1
v0.13.0
v0.12.0
v0.11.0
v0.10.0
v0.9.0
v0.8.3
v0.8.2
v0.8.1
v0.8.0
0.8beta1
0.7
0.7beta4
0.7beta3
0.7beta2
v0.6
v0.6b3
v0.6b2
v0.6b1
v0.5.0
v0.5.0b1
v0.4.3
v0.4.2
v0.4.1
v0.4
v0.4b2
v0.4b1
v0.3
v0.3b1
v0.2.1
v0.1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
WhyNotHugo/python-barcode#91
Reference in a new issue
WhyNotHugo/python-barcode
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?