Skip to content

Fix NumPy 2.0 compatibility by replacing deprecated np.asfarray #591

@gabriel-filincowsky

Description

@gabriel-filincowsky

First, I'd like to thank the maintainers for creating and maintaining the excellent ComfyUI LayerStyle node - it's an incredibly valuable tool for advanced image compositing and blending operations in ComfyUI workflows! Your work on providing professional-grade layer effects is greatly appreciated.

Description

Users with NumPy 2.0+ installations encounter an AttributeError: np.asfarraywas removed in the NumPy 2.0 release. Usenp.asarray with a proper dtype instead. when trying to use any LayerStyle blending operations. This prevents all image blending functionality from working with modern NumPy versions.

Current Behavior

  • LayerStyle nodes work fine with NumPy 1.x installations
  • Throws AttributeError when NumPy 2.0+ is installed
  • Error occurs during image preparation in blending operations

Steps to Reproduce

  1. Install NumPy 2.0 or later
  2. Add any LayerStyle blending node to ComfyUI workflow
  3. Connect image inputs and attempt to execute
  4. Error occurs during blending operation

Error Details

AttributeError: `np.asfarray` was removed in the NumPy 2.0 release. Use `np.asarray` with a proper dtype instead.
  File "ComfyUI\custom_nodes\comfyui_layerstyle\py\image_blend_v2.py", line 74, in image_blend_v2
    _comp = chop_image_v2(_canvas, _layer, blend_mode, opacity)
  File "ComfyUI\custom_nodes\comfyui_layerstyle\py\imagefunc.py", line 368, in chop_image_v2
    backdrop_prepped = np.asfarray(background_image.convert('RGBA'))

Root Cause

The issue occurs because:

  1. np.asfarray was deprecated and removed in NumPy 2.0
  2. Code uses outdated NumPy API incompatible with NumPy 2.0+
  3. Modern NumPy installations break all LayerStyle functionality

Environment

  • ComfyUI with NumPy 2.0+
  • ComfyUI LayerStyle custom nodes
  • Modern Python environments with updated NumPy

Proposed Solution

Replace deprecated np.asfarray with np.asarray and explicit dtype:

Changes needed in py/imagefunc.py around lines 368-369:

# Before:
backdrop_prepped = np.asfarray(background_image.convert('RGBA'))
source_prepped = np.asfarray(layer_image.convert('RGBA'))

# After:
backdrop_prepped = np.asarray(background_image.convert('RGBA'), dtype=np.float64)
source_prepped = np.asarray(layer_image.convert('RGBA'), dtype=np.float64)

Why This Matters

  1. Critical compatibility: Enables LayerStyle nodes with modern NumPy versions
  2. User experience: Eliminates crashes for users with updated environments
  3. Future-proofing: Ensures compatibility with current and future NumPy releases
  4. Widespread impact: Affects all LayerStyle users with NumPy 2.0+

Testing

  • NumPy compatibility: Confirmed works with both NumPy 1.x and 2.x
  • Output quality: Blending effects identical across NumPy versions
  • Blend modes: All blend modes (multiply, screen, overlay, etc.) work correctly
  • Performance: No degradation in processing speed
  • Backward compatibility: Existing workflows unaffected

Impact

  • Risk: Very low - direct API replacement with identical behavior
  • Scope: Affects only numpy array creation, no functional changes
  • Compatibility: Fully backward and forward compatible

This fix restores full functionality for users with modern NumPy installations while maintaining all existing behavior. Your continued work on ComfyUI LayerStyle is invaluable to the community - thank you for maintaining such a comprehensive and professional layer effects toolkit!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions