avalonv / reCBZ

Utility for converting and optimizing comics for e-readers & mobile devices
GNU General Public License v3.0
87 stars 6 forks source link

Allow preserving aspect ratio #19

Open bust4cap opened 1 year ago

bust4cap commented 1 year ago

images are resized to the exact output resolution without keeping their correct aspect ratio. ive attempted to fix this. ive tested with both up- and downscaling and it worked perfectly for me, but please test it for yourself first too. (i commented out the old method) archive.py starting at line 131:

    # downscaling
    if (width > n_width and height > n_height
        and not options['nodown']):
        #img = img.resize((new_size), config.RESAMPLE_TYPE)
        img.thumbnail((new_size), config.RESAMPLE_TYPE)

    # upscaling
    elif not options['noup']:
        #img = img.resize((new_size), config.RESAMPLE_TYPE)
        width_ratio = (n_width/float(width))
        height_corrected = int((float(height)*float(width_ratio)))
        img = img.resize((n_width,height_corrected), config.RESAMPLE_TYPE)
        if img.size[0] > n_width or img.size[1] > n_height:
            img.thumbnail((new_size), config.RESAMPLE_TYPE)
avalonv commented 1 year ago

Hi. I tested it and it appears to work as intended.

However, I don't really understand the use case for this. Resizing, whether called explicitly or by --profile, implies modifying the aspect ratio. Perhaps it's not clear by the comment, but what I mean by "preserve aspect ratio", is try to preserve the orientation of landscape images.

The fixed layout specification for ebooks says that content should fill the entire screen, so the current implementation is intentional. See this. Having images not be resized to the size the user specified seems counterintuitive to me, and the whole point a fixed layout ebook is that it should behave consistently regardless of what the input image was.

Most manga and comics don't follow exactly a 3:4 format, and will be stretched to some degree, but this is usually pretty minor. Tankobon published in the West typically follow a 130x190 aspect ratio, which appears to be very similar to western comics.

avalonv commented 1 year ago

Though I can see why an option to preserve aspect ratio would be useful. The default method could be a problem when dealing with webcomics, cause there isn't really a standard size, and stretching a perfectly square image into a (generally) 3:4 screen would probably look really bad, so I might implement the thumbnail method there.

Thanks for the suggestion. I will try to add this in the next week.

avalonv commented 1 year ago

For the time being, if you wanna preserve the aspect ratio, you can use --size 0x0 (or --noup and --nodown simultaneously, I think. Nvm I made them mutually exclusive a while ago).

bust4cap commented 1 year ago

it should fill as much of the viewport as possible, not distort images to fill every last pixel of it. no one does that, not the publishers, not online scanlations, not kindle comic converter. you could add an option to specifically not keep the correct aspect ratio, but keeping it in tact should ALWAYS be the standard. you wouldnt stretch an old 4:3 snes video game to 16:9 just because you have an hd tv now. that would look just as horrible as stretching a "nearly" 4:3 image to 4:3, no matter how "minor" it may seem.

avalonv commented 1 year ago

Okay, you're right and I apologise, it seems I really misunderstood the spec.

I'll be at least a few weeks before I can work on this, I'm in the middle of moving. In the meantime, you can make it your patch into a full pull request if you want.

snarkyyy commented 1 year ago

I tried to add this: https://github.com/avalonv/reCBZ/pull/20