{"record":{"id":"ec1c5074b7f7ab92","repo":"crewAIInc/crewAI","slug":"pillow-is-required-for-image-resizing","errorCode":null,"errorMessage":"Pillow is required for image resizing","messagePattern":"Pillow is required for image resizing","errorType":"exception","errorClass":"ProcessingDependencyError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/processing/transformers.py","lineNumber":39,"sourceCode":") -> ImageFile:\n    \"\"\"Resize an image to fit within the specified dimensions.\n\n    Args:\n        file: The image file to resize.\n        max_width: Maximum width in pixels.\n        max_height: Maximum height in pixels.\n        preserve_aspect_ratio: If True, maintain aspect ratio while fitting within bounds.\n\n    Returns:\n        A new ImageFile with the resized image data.\n\n    Raises:\n        ProcessingDependencyError: If Pillow is not installed.\n    \"\"\"\n    try:\n        from PIL import Image\n    except ImportError as e:\n        raise ProcessingDependencyError(\n            \"Pillow is required for image resizing\",\n            dependency=\"Pillow\",\n            install_command=\"pip install Pillow\",\n        ) from e\n\n    content = file.read()\n\n    with Image.open(io.BytesIO(content)) as img:\n        original_width, original_height = img.size\n\n        if original_width <= max_width and original_height <= max_height:\n            return file\n\n        if preserve_aspect_ratio:\n            width_ratio = max_width / original_width\n            height_ratio = max_height / original_height\n            scale_factor = min(width_ratio, height_ratio)\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/processing/transformers.py#L21-L57","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install Pillow: pip install Pillow (or add it to your project's dependencies / install the image extras of crewai-files if provided).","Pin it in pyproject/requirements so environments are reproducible.","Catch ProcessingDependencyError and check .install_command / .dependency for a self-healing message to the operator.","Pre-resize images upstream (client-side) so AUTO never needs to resize in an environment without Pillow."],"exampleFix":"# before\n# environment without Pillow\nnew_img = resize_image(file, max_width=1024, max_height=1024)  # ProcessingDependencyError\n\n# after\n# shell: pip install Pillow\nnew_img = resize_image(file, max_width=1024, max_height=1024)","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"PIL\") is None and handling == FileHandling.AUTO:\n    raise RuntimeError(\"FileHandling.AUTO with images requires Pillow: pip install Pillow\")","typeGuard":null,"tryCatchPattern":"from crewai_files.processing.exceptions import ProcessingDependencyError\n\ntry:\n    out = resize_image(file, max_width, max_height)\nexcept ProcessingDependencyError as e:\n    if e.dependency == \"Pillow\":\n        raise RuntimeError(f\"missing optional dependency; run: {e.install_command}\") from e\n    raise","preventionTips":["Add Pillow to the deployment dependency set whenever images are processed.","Check importlib.util.find_spec('PIL') at startup and fail fast with a clear message.","Use the exception's .dependency and .install_command fields for actionable operator messages."],"tags":["pillow","dependency","image","resize","optional-dependency"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}