Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow preserving aspect ratio #19

Open
bust4cap opened this issue Dec 16, 2022 · 6 comments
Open

Allow preserving aspect ratio #19

bust4cap opened this issue Dec 16, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@bust4cap
Copy link

bust4cap commented Dec 16, 2022

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)
@bust4cap bust4cap changed the title Resized images dont keep their correct aspect ratio [Fix] Resized images dont keep their correct aspect ratio Dec 16, 2022
@avalonv
Copy link
Owner

avalonv commented Dec 18, 2022

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
Copy link
Owner

avalonv commented Dec 18, 2022

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
Copy link
Owner

avalonv commented Dec 18, 2022

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).

@avalonv avalonv added the enhancement New feature or request label Dec 18, 2022
@avalonv avalonv changed the title [Fix] Resized images dont keep their correct aspect ratio Allow preserving aspect ratio. Dec 18, 2022
@avalonv avalonv changed the title Allow preserving aspect ratio. Allow preserving aspect ratio Dec 18, 2022
@bust4cap
Copy link
Author

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
Copy link
Owner

avalonv commented Dec 22, 2022

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
Copy link

I tried to add this: #20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants