OpenCV haveImageWriter_0
Ask OpenCV whether it can save to a filename, before you try
- bool
haveImageWriter_0 tells you whether OpenCV could write an image to a given filename. One string in, one boolean out. It's the mirror image of haveImageReader_0 - but with an important difference you should know before you trust it.
How it works
Under the hood it's cv2.haveImageWriter(filename), and unlike the reader check, this one is only an extension test. OpenCV looks at the file suffix - .png, .jpg, .webp, whatever - and checks whether a matching image codec is compiled in. It does not touch the filesystem, does not check if the directory exists, and does not verify you can actually write there. So it answers "is this file type writable?" not "will this write succeed?". A False means the extension is unsupported and you should change it. A True means the type is fine - and your write can still fail on permissions or a missing folder.
Where you'd use it
Honestly? Rarely, and that's fine. The main scenario is a workflow that builds a filename from string nodes - maybe appending an extension to a user-supplied base name - where you want to fail fast with a readable message if someone typed .tiff9 or a made-up suffix. You gate the imwrite node on this check and route to an error path otherwise. If you always save through SaveImage with a fixed extension, you'll never need it. It's a guardrail node, not a workhorse.
Input and output
filename(STRING) - the path/name you plan to save to. The extension is the only thing that matters.bool(BOOLEAN) -Trueif OpenCV's build can encode that file type,Falseotherwise.
Install
Same as every node in the opencv-comfyui pack:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or search "OpenCV" in ComfyUI Manager. Then:
pip install opencv-contrib-python
No model downloads. The pip opencv-contrib-python build includes the standard set of encoders (PNG, JPEG, WebP, and friends), so for any normal extension this returns True.
Gotchas
The trap is assuming True means "the write will work". It doesn't - it's a codec check, and a perfectly valid .png path in a non-existent directory will still return True and then fail on save. If you're using this to build reliable workflows, remember it only covers half the failure surface. And note this node is pure extension logic, so it never touches an image: you don't need to convert anything, and it plays nice with the rest of the pack's string utilities even though most OpenCV nodes here demand NPARRAY inputs. One of the more painless nodes in the pack - precisely because it does so little.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| filename | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| bool | BOOLEAN | — |