multiSnow / mcomix3

End of Fork
Other
97 stars 39 forks source link

Option "Show only one page for wide images" does not work #152

Closed sakkamade closed 3 years ago

sakkamade commented 3 years ago

The option "Preferences -> Behaviour -> Show only one page where appropriate -> Only for wide images" does not work, i.e. the title page stay separate (the images are portrait ones). Whereas if I choose "Never", "Always" or "Only for title page" in the same drop-down, these options work as they should.

However more than that, I would like to see another, separate option "Show title page separately." And if developer willing to implement this, I will rather close this and open another issue as Feature Request instead, where I will elaborate more upon it.

multiSnow commented 3 years ago

'Only for wide images' means the wide image will show without 'beside' image.

It means the odd page before the wide image will also show as one page with 'Only for wide images' (or the even page for 'Always', since the title is also 'only one page'), and all pages after wide image will be 're-aligned'.

e.g. Consider such a book with pages: 1narrow, 2wide, 3narrow, 4narrow

For both 'Only for wide images' and 'Always' option, the first page will show as only one page, since the second page is forced to be only one page.

sakkamade commented 3 years ago

I presume I have mentioned:

(the images are portrait ones)

The portrait image means narrow image.

sakkamade commented 3 years ago

Ah, I see, the first (title) image is 70px wider than the following...

Sorry, I have also tested archive containing landscape images, but not with proper portrait ones.

sakkamade commented 3 years ago

Thank you! But I'll ask then if I shall create the Feature request which I mentioned earlier? Since I still consider that important.

sakkamade commented 3 years ago

Ah, I see, the first (title) image is 70px wider than the following...

I must slightly elaborate on that here.

  1. Images which shown separately (regarded as landscape ones by the program): 4230x4219 (width-height) 4288x4260

  2. And which considered to be portrait ones: 4230x4256 4212x4268 4202x4268

As you can see in #1 the width is few pixels higher than height. Perhaps the program should allow some ~15px (or ~20px in my situation) leeway on width for such cases?

EDIT: Or perhaps not pixels but percents? Like, change the property for "Only wide images" from present (<=100%)x100% to (<=103%)x100% (width-height)?

sakkamade commented 3 years ago

I will try to make myself more plain.

As I see it, currently, the wide image considered the image which has higher width than height, even if in one pixel.

Therefore if we take 100% as difference between width and height 1:1, the >100% would denote ratio of ">1:1" or "1:<1", which is the landscape image; accordingly, the <100% is "1:>1" or "<1:1" ratio, which is the portrait one.

Taking aforesaid into account, I am asking would it be alright if the option "Only for wide images" would treat the images which have the ratio "<1.1:1" as portrait?

sakkamade commented 3 years ago
  1. Images which shown separately (regarded as landscape ones by the program): 4230x4219 (width-height) 4288x4260

  2. And which considered to be portrait ones: 4230x4256 4212x4268 4202x4268

Taking these values as an example:

  1. 4230x4219 = 100.26% 4288x4260 = 100.65%
  2. 4230x4256 = 99.39% 4212x4268 = 98.69%
sakkamade commented 3 years ago

This is where I should meddle in, for me to achieve what I want, I understand.

https://github.com/multiSnow/mcomix3/blob/d003e64c2559a238e59f4f9eb4ec2a60dad5ac6f/mcomix/mcomix/image_handler.py#L189-L200

As far as I see it, the easiest solution would be to get 2% of pixbuf.get_width(), and then append them to pixbuf.get_width() in line 193. The problem is that I am completely clueless about how can I get those 2%.

Can anyone point me in the right direction?

sakkamade commented 2 years ago

For anyone interested, I actually need to subtract 2% from the width, and for that I did following:

--- a/mcomix/mcomix/image_handler.py
+++ b/mcomix/mcomix/image_handler.py
@@ -191,12 +191,13 @@ class ImageHandler(object):
                 return False
             pixbuf = self._get_pixbuf(page - 1)
             width, height = pixbuf.get_width(), pixbuf.get_height()
+            smallwidth = width-width*0.02
             if prefs['auto rotate from exif']:
                 rotation = image_tools.get_implied_rotation(pixbuf)
                 assert rotation in (0, 90, 180, 270)
                 if rotation in (90, 270):
-                    width, height = height, width
-            if width > height:
+                    smallwidth, height = height, smallwidth
+            if smallwidth > height:
                 return True

         return False

Information was taken from: https://huaihsuan-peng.medium.com/python-tools-topic-1-basic-calculations-variables-2bae2fd1a46a