crewAIInc/crewAI · error · ProcessingDependencyError

Pillow is required for image resizing

Error message

Pillow is required for image resizing

What it means

resize_image() in crewai_files.processing.transformers lazily imports PIL; if Pillow is not installed it raises ProcessingDependencyError('Pillow is required for image resizing') with dependency='Pillow' and install_command='pip install Pillow'. The library keeps Pillow optional, so the error appears only when an image actually needs resizing (e.g. AUTO mode downsizing an oversized image).

Source

Thrown at lib/crewai-files/src/crewai_files/processing/transformers.py:39

) -> ImageFile:
    """Resize an image to fit within the specified dimensions.

    Args:
        file: The image file to resize.
        max_width: Maximum width in pixels.
        max_height: Maximum height in pixels.
        preserve_aspect_ratio: If True, maintain aspect ratio while fitting within bounds.

    Returns:
        A new ImageFile with the resized image data.

    Raises:
        ProcessingDependencyError: If Pillow is not installed.
    """
    try:
        from PIL import Image
    except ImportError as e:
        raise ProcessingDependencyError(
            "Pillow is required for image resizing",
            dependency="Pillow",
            install_command="pip install Pillow",
        ) from e

    content = file.read()

    with Image.open(io.BytesIO(content)) as img:
        original_width, original_height = img.size

        if original_width <= max_width and original_height <= max_height:
            return file

        if preserve_aspect_ratio:
            width_ratio = max_width / original_width
            height_ratio = max_height / original_height
            scale_factor = min(width_ratio, height_ratio)

View on GitHub (pinned to 754d7323be)

Solutions

  1. Install Pillow: pip install Pillow (or add it to your project's dependencies / install the image extras of crewai-files if provided).
  2. Pin it in pyproject/requirements so environments are reproducible.
  3. Catch ProcessingDependencyError and check .install_command / .dependency for a self-healing message to the operator.
  4. Pre-resize images upstream (client-side) so AUTO never needs to resize in an environment without Pillow.

Example fix

# before
# environment without Pillow
new_img = resize_image(file, max_width=1024, max_height=1024)  # ProcessingDependencyError

# after
# shell: pip install Pillow
new_img = resize_image(file, max_width=1024, max_height=1024)
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

if importlib.util.find_spec("PIL") is None and handling == FileHandling.AUTO:
    raise RuntimeError("FileHandling.AUTO with images requires Pillow: pip install Pillow")

Try / catch

from crewai_files.processing.exceptions import ProcessingDependencyError

try:
    out = resize_image(file, max_width, max_height)
except ProcessingDependencyError as e:
    if e.dependency == "Pillow":
        raise RuntimeError(f"missing optional dependency; run: {e.install_command}") from e
    raise

Prevention

When it happens

Trigger: Running with FileHandling.AUTO (or calling resize_image directly) on an image that exceeds max_width/max_height while Pillow is absent from the environment. Also triggered in slim Docker images or production installs where crewai-files was installed without the image extras.

Common situations: pip install crewai-files without extras in CI/CD; alpine/slim Docker base images; dev machine had Pillow transitively (via another package) but the deploy env does not; venv recreated without Pillow.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/ec1c5074b7f7ab92. Report an issue: GitHub.