Skip to content

Removes image fragmentation from bitImageColumn - #810

Open
dalpil wants to merge 2 commits into
python-escpos:masterfrom
dalpil:fix-bitimagecolumn-fragmentation
Open

dalpil wants to merge 2 commits into
python-escpos:masterfrom
dalpil:fix-bitimagecolumn-fragmentation

Conversation

@dalpil

@dalpil dalpil commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Description

The bitImageColumn (ESC *) method for printing images does not need image fragmentation, as it's already built into the command itself. Image data is always sent in chunks with a height of 8 or 24.

I also simplified the to_column_format-method a bit.

I'm not entirely sure why the line feed is being set to 16. I feel like it should be set to 24 for double-density images. This does not seem to matter though, as I can push the line feed up to 50 until i start getting white horizontal lines in my prints.

I looked into some other implementations, and most of them seem to set the line-feed to 24, but it could just as well be set to 0 it seems, at least on my printer.

Since I don't know why it's being set to 16 I'll refrain from changing it, as it doesn't seem to matter on my printer.

Anyhow, here's a comparison of two bitImageColumn-prints before and after my changes (i set fragment_height to 100 for the print on the left):

IMG_1348

Please let me know if the PR can be improved in any way, I'm open for discussion.

Closes #802.

Tested with

Epson TM-m30

Fragmentation is already built into the ESC * command, so there's no
need to fragment images.
@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.28%. Comparing base (106e251) to head (5c12f8d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #810      +/-   ##
==========================================
- Coverage   79.33%   79.28%   -0.05%     
==========================================
  Files          21       21              
  Lines        1742     1738       -4     
  Branches      241      241              
==========================================
- Hits         1382     1378       -4     
  Misses        282      282              
  Partials       78       78              
Flag Coverage Δ
unittests 79.28% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/escpos/escpos.py 79.33% <100.00%> (ø)
src/escpos/image.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@belono

belono commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Hi @dalpil and thank you for opening this request!

My TM-H6000 is not affected by the gaps issue but I can confirm no regressions in 'bitImageColumn' mode after this patch, at least for my printer:

Image1

Note that the little white bands are not gaps.

In relation with the line-width size I can confirm the same behavior as your printer, no difference between 0 and 49, starting to see the gap at 50 units:

IMG_20261102_105438_1

Note the thin gap in the third print-out.

I also don't know why this value was set to 16 but it has been like this since @miracle2k wrote the implementation of the image() method back in 2016. I assume that is a "safe" value but is true that is not an intuitive one. Maybe we should wrap it into a constant so it would be more legible. We could extend and make use of the line spacing constants to make the bitImageColumn fragment of code more understandable/readable.

@belono belono left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a couple of debatable suggestions so that we can discuss them with the rest of the contributors.

Comment thread src/escpos/escpos.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outp = [LINESPACING_FUNCS[180] + int.to_bytes(0)] # Disable linespacing

Additionally int.to_bytes(0) can be wrapped into a constant named like LINESPACING_DISABLE or similar

Comment thread src/escpos/escpos.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outp.append(LINESPACING_RESET) # Reset line-feed size

We take profit of the existing constant LINESPACING_RESET

@dalpil

dalpil commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

It's interesting that you're not getting any gaps in your prints. I had a look in the TM-H6000 Developer Guide and it seems like the "ESC *" command (section 4-8 in the guide) should behave like it does on my printer, so I'd expect gaps to appear in your prints (from the master branch) as well.

Did you specify a fragment_height of 100 when printing the images, or something else that isn't divisible by 24? I.e.

p.image('david.png', fragment_height=100, impl='bitImageColumn')

The use of existing constants seems like a good idea, I'll make sure to apply the suggested changes. 👍

@belono

belono commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Did you specify a fragment_height of 100 when printing the images, or something else that isn't divisible by 24?

You are right, I left fragment_height as default.

Indeed, I can reproduce the gaps when I specify fragment_height=100 in master and, after the patch, the gaps disappear:
David_100_frag_height

p.image("david_512w.jpg", True, True, fragment_height=100, impl="bitImageColumn", center=False)

I also tested changing the line-spacing from current 16 to 0 and the results are the same: gaps on master and no gaps on the patched version after adding the fragment_height=100 parameter.

@dalpil

dalpil commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Perfect, that's the kind of gaps that I'm trying to get rid of. Thank you for reproducing the issue.

I'll update the PR with the suggested changes later this evening.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image fragmentation logic causes horizontal white stripes with "bitImageColumn" for certain fragment_height values

2 participants