コード例 #1
0
ファイル: ActionCenterPath.py プロジェクト: VonAncken/PFS
    def Execute(self):
        try:
            width, height = PILBackend.GetImageSize(
                self.__picture.GetFilename())
        except:
            return

        ratio = Aspect.ToFloat(self.__aspect)
        picRatio = width / float(height)
        if picRatio > ratio:
            scaledWidth = height * ratio
            scaledHeight = height
        else:
            scaledWidth = width
            scaledHeight = width / ratio

        centerRect = (int(round((width - scaledWidth) / 2.0)),
                      int(round((height - scaledHeight) / 2.0)),
                      int(round(scaledWidth)), int(round(scaledHeight)))
        self.__picture.SetStartRect(centerRect)
        self.__picture.SetTargetRect(centerRect)
コード例 #2
0
    def Execute(self):
        try:
            width, height = PILBackend.GetImageSize(
                self.__picture.GetFilename())
        except:
            return

        if self.__picture.GetWidth() == -1:
            # FIXME: stupid if
            self.__picture.SetWidth(width)
            self.__picture.SetHeight(height)

        ratio = Aspect.ToFloat(self.__aspect)
        if width < height:
            # portrait
            startRect = (0, 0, width, width / ratio)
            targetRect = (0, height - (width / ratio), width, width / ratio)
        else:
            scaledWidth = width * 0.75
            startRect = (0, 0, width, width / ratio)
            d = random.randint(0, 3)
            if d == 0:
                targetRect = (0, 0, scaledWidth, scaledWidth / ratio)
            elif d == 1:
                targetRect = (0, height - (scaledWidth / ratio), scaledWidth,
                              scaledWidth / ratio)
            elif d == 2:
                targetRect = (width - scaledWidth, 0, scaledWidth,
                              scaledWidth / ratio)
            elif d == 3:
                targetRect = (width - scaledWidth,
                              height - (scaledWidth / ratio), scaledWidth,
                              scaledWidth / ratio)

        if random.randint(0, 1):
            targetRect, startRect = startRect, targetRect

        self.__picture.SetStartRect(startRect)
        self.__picture.SetTargetRect(targetRect)