Fix image handling: Remove dependency on comfy.utils.to_uint8
- Replaced comfy.utils.to_uint8() with standard np.array() for better compatibility - Added missing numpy import in preset_creator_node.py - Functions now work with all ComfyUI versions - Maintained same tensor format [1,H,W,C] for ComfyUI compatibility - Tested and verified working correctly
This commit is contained in:
@@ -236,7 +236,7 @@ def _get_preview_info(model_id: str) -> Dict[str, Any]:
|
||||
def _pil_to_image_tensor(pil: Image.Image) -> torch.Tensor:
|
||||
"""Convert PIL Image to ComfyUI tensor format [1,H,W,C]"""
|
||||
img = pil.convert("RGB")
|
||||
arr = comfy.utils.to_uint8(img) # numpy array uint8
|
||||
arr = np.array(img) # numpy array uint8
|
||||
t = torch.from_numpy(arr).float() / 255.0
|
||||
return t.unsqueeze(0) # batch = 1
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from datetime import datetime
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import torch
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
import comfy.utils
|
||||
@@ -20,7 +21,7 @@ import folder_paths
|
||||
def _pil_to_image_tensor(pil: Image.Image) -> torch.Tensor:
|
||||
"""Convert PIL Image to ComfyUI tensor format [1,H,W,C]"""
|
||||
img = pil.convert("RGB")
|
||||
arr = comfy.utils.to_uint8(img) # numpy array uint8
|
||||
arr = np.array(img) # numpy array uint8
|
||||
t = torch.from_numpy(arr).float() / 255.0
|
||||
return t.unsqueeze(0) # batch = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user