def screenshot(self, return_bytes=False):
        """Take a screenshot of the current screen and return the base64 encoded image."""
        temp_dir = Path(tempfile.gettempdir())
        path = temp_dir / f"screenshot_{uuid4().hex}.png"

        screenshot = pyautogui.screenshot()
        
        # Save original screenshot
        screenshot.save(str(path))
        print(f"Original file size: {os.path.getsize(path)} bytes")

        # Only apply scaling if enabled and necessary
        if self._scaling_enabled and self.scaling_config["mode"] != ScalingMode.NONE:
            from PIL import Image

            # Get target dimensions
            if self.scaling_config["mode"] == ScalingMode.FIXED and self.scaling_config["target_resolution"]:
                # Fixed mode - use target resolution directly
                target_width = self.scaling_config["target_resolution"]["width"]
                target_height = self.scaling_config["target_resolution"]["height"]
            else:
                # Use relative scaling
                scale = self.scaling_config.get("scale_factor", 1.0)
                target_width = int(self.width * scale)
                target_height = int(self.height * scale)
            
            # Only resize if dimensions are different
            if target_width != self.width or target_height != self.height:
                print(f"Resizing screenshot to {target_width}x{target_height}")
                with Image.open(path) as img:
                    # Resize with high-quality downsampling
                    img = img.resize((target_width, target_height), Image.Resampling.LANCZOS)
                    # Save with optimization
                    img.save(path, optimize=True, quality=90)

        if path.exists():
            print(f"Final screenshot size: {os.path.getsize(path)} bytes")
            if return_bytes:
                return path.read_bytes()
            else:
                base64_image = base64.b64encode(path.read_bytes()).decode()
                path.unlink()  # Remove the temporary file

            return {
                "type": "image",
                "source": {
                    "type": "base64",
                    "media_type": "image/png",
                    "data": base64_image,
                }
            }
                
        return {"text": "Failed to take screenshot"}
Take a screenshot of the current screen and return the base64 encoded image.
src/upsonic/server/level_utilized/cu/computer.py