Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Dev auto aspect ratio #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ optional arguments:
-o OFFSET, --offset OFFSET
UTC time offset in hours, must be less than or equal
to +10
--auto-aspect-ratio better for 16:10 aspect ratio desktop. works only on
default level!
-l {4,8,16,20}, --level {4,8,16,20}
increases the quality (and the size) of each tile.
possible values are 4, 8, 16, 20
Expand Down
16 changes: 16 additions & 0 deletions himawaripy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def parse_args():
group.add_argument("-o", "--offset", type=int, dest="offset", default=10,
help="UTC time offset in hours, must be less than or equal to +10")

parser.add_argument("--auto-aspect-ratio", action="store_true", dest="auto_aspect_ratio", default=False,
help="better for 16:10 aspect ratio desktop. works only on default level!")
parser.add_argument("-l", "--level", type=int, choices=[4, 8, 16, 20], dest="level", default=4,
help="increases the quality (and the size) of each tile. possible values are 4, 8, 16, 20")
parser.add_argument("-d", "--deadline", type=int, dest="deadline", default=6,
Expand Down Expand Up @@ -168,6 +170,20 @@ def thread_main(args):
tile = Image.open(io.BytesIO(tiledata))
png.paste(tile, (WIDTH * x, HEIGHT * y, WIDTH * (x + 1), HEIGHT * (y + 1)))

if args.auto_aspect_ratio and args.level == 4:
MARGIN = 166

height = int(png.height + MARGIN * 2)
width = int(height * 1.6)

png_new = Image \
.new('RGB', (width, height), 0)

png_new.paste(png, (int(width / 2 - png.width / 2), MARGIN))

del png
png = png_new

for file in iglob(path.join(args.output_dir, "himawari-*.png")):
os.remove(file)

Expand Down