advanced-loopback-for-sd-webui icon indicating copy to clipboard operation
advanced-loopback-for-sd-webui copied to clipboard

Move up (Direction Y 0.1) doesn't seem to work

Open DarceyLloyd opened this issue 1 year ago • 1 comments

Hi,

Awesome script, been looking for something like this for ages.

One issue I'm having though is that it doesn't want to move up, it goes x -0.1 to 0.1 and y -0.1 fine, but when Direction Y is set to 0.1 it doesn't move up.

Is the zoom center/origin at top center or center center? Only thing I can think that would have this effect?

DarceyLloyd avatar Aug 04 '23 15:08 DarceyLloyd

This will do it but just got to watch the Y value so that it doesn't move up faster than you zoom in.


    def zoom_into(self, img, zoom, direction_x, direction_y):
        if zoom < 1:
            raise ValueError("Zoom must be greater or equal to 1")

        neg = lambda x: 1 if x > 0 else -1
        if abs(direction_x) > 1: direction_x = neg(direction_x) * 0.999999999999999
        if abs(direction_y) > 1: direction_y = neg(direction_y) * 0.999999999999999

        w, h = img.size
        center_x = w / 2
        center_y = h / 2

        # Calculate the new center based on direction_x and direction_y
        x = center_x + direction_x * (w / (4 * zoom))
        y = center_y - direction_y * (h / (4 * zoom))

        # Calculate the cropping coordinates
        new_w = w / zoom
        new_h = h / zoom
        left = x - new_w / 2
        top = y - new_h / 2
        right = x + new_w / 2
        bottom = y + new_h / 2

        # Crop and resize
        img = img.crop((left, top, right, bottom))
        return img.resize((w, h), Image.LANCZOS)

DarceyLloyd avatar Aug 04 '23 16:08 DarceyLloyd