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

Support multiscale images; specify output size #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

IrisRainbowNeko
Copy link

@IrisRainbowNeko IrisRainbowNeko commented Feb 8, 2025

Make --scale argument support input of multiple scales.

  • --scale 0.25 resize the cursor to 1/4 of its original size.
  • --scale "[0.125,0.25,0.5]" resize the cursor to multiple scales and put them into one cursor file.

Add --size argument to support specify multiple output size.

  • --size 32 resize the cursor to 32px.
  • --size "[32,48,64]" resize the cursor to multiple sizes and put them into one cursor file.

image

@IrisRainbowNeko IrisRainbowNeko changed the title Support multiscale images Support multiscale images; specify output size Feb 8, 2025
Comment on lines 53 to +64
if args.scale:
scale.apply_to_frames(cursor.frames, scale=args.scale)
scales = eval(args.scale)
if isinstance(scales, (int, float)):
scale.apply_to_frames(cursor.frames, scale=scales)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, scales=scales)
elif args.size:
sizes = eval(args.size)
if isinstance(sizes, (int, float)):
scale.apply_to_frames(cursor.frames, size=sizes)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, sizes=sizes)
Copy link
Owner

Choose a reason for hiding this comment

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

Please do not use eval. This is a security nightmare when using this in any form of automation.

Comment on lines 39 to +50
if args.scale:
scale.apply_to_frames(cursor.frames, scale=args.scale)
scales = eval(args.scale)
if isinstance(scales, (int, float)):
scale.apply_to_frames(cursor.frames, scale=scales)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, scales=scales)
elif args.size:
sizes = eval(args.size)
if isinstance(sizes, (int, float)):
scale.apply_to_frames(cursor.frames, size=sizes)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, sizes=sizes)
Copy link
Owner

Choose a reason for hiding this comment

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

Do not duplicate code.

cursor.hotspot = (int(hx * scale), int(hy * scale))


def apply_to_frames_MS(frames: List[CursorFrame], *, scales: List[float] = None,
Copy link
Owner

Choose a reason for hiding this comment

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

What is _MS? Use a more sensible name.

Comment on lines +23 to +32
if scales is not None:
for scale in scales:
frames_s = [frame.clone() for frame in frames]
apply_to_frames(frames_s, scale=scale)
frames_MS.extend(frames_s)
else:
for size in sizes:
frames_s = [frame.clone() for frame in frames]
apply_to_frames(frames_s, size=size)
frames_MS.extend(frames_s)
Copy link
Owner

Choose a reason for hiding this comment

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

Does this need to be one function? It's basically two separate functions.

for scale in scales:
frames_s = [frame.clone() for frame in frames]
apply_to_frames(frames_s, scale=scale)
frames_MS.extend(frames_s)
Copy link
Owner

Choose a reason for hiding this comment

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

Why are you concatenating frames of different sizes? This is wrong. A frame contains multiple images of different sizes. When scaling an animated cursor, you keep the same number of frames, but each frame will have more images.

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.

2 participants