Files
av-club/tasks/convert-image/TASK.md
T
pastilhasandClaude Opus 5 c69f6d12a3 Convert Image, and HEIC opens because av-club already knew how
the fourth task. same shape as the other three — beside the original, skip an
existing output, skip a file already in the target format, delete only when asked
and only after the write.

/v1/sharp gets the same path mode /v1/ffmpeg got, for the same reason: the file
browser and the commander both already have the file.

HEIC IS THE POINT OF THIS ONE, and nothing in the task does anything about it.
`decodable.ts` has routed HEIC through ImageMagick since before I touched this
plugin, because the libheif inside sharp is built without the HEVC decoder — a
HEIC reads its own header fine and then fails on the pixels, which looks exactly
like a corrupt file and is not one. the task simply names `.heic` in its trigger
and asks. the photographs open.

I had diagnosed that gap independently against the file browser's thumbnails and
concluded a system decoder would be needed, twice telling the owner these files
could not be read. this plugin had already solved it and documented why. worth the
note: the answer was in the tree.

a path has no stored `format`, so sharp's `metadata()` supplies it — and that only
reads the header, which is precisely the part of a HEIC that works, so it correctly
identifies the files needing ImageMagick.

`rotate` with no argument is in every pipeline: it applies the EXIF orientation and
drops the tag. without it a portrait photo from a phone converts to a landscape
image that viewers rotate back, until one does not.

max_dimension shrinks to fit and never enlarges. quality 82 for jpeg and webp, 55
for avif — where a photograph stops looking better and only gets bigger.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 02:28:06 +01:00

53 lines
2.1 KiB
Markdown

---
name: Convert Image
description: Convert photos between formats through av-club — including HEIC from a phone, which most tools cannot read. Optionally shrink to fit a maximum size.
category: Image
version: 1
mode: script
language: typescript
inline: ask
args:
- file_path
inputs:
file_path:
type: string
description: An image, or a folder to convert recursively.
target_format:
type: string
default: jpeg
options: [jpeg, png, webp, avif, tiff]
description: Format to convert to.
max_dimension:
type: string
default: original
options: [original, "3000", "2000", "1600", "1200", "800"]
description: Shrink so neither side exceeds this, keeping the aspect ratio. Never enlarges.
delete_source:
type: boolean
default: false
description: Delete each source file once its conversion has been written.
trigger:
- type: file
extensions: [heic, heif, jpg, jpeg, png, webp, avif, tif, tiff, gif, bmp, jp2]
- type: directory
---
# Convert Image
Writes the result **beside the original** — `IMG_3707.HEIC` becomes `IMG_3707.jpeg` in the same folder.
**HEIC works here**, which is worth saying because it does not work in most places. Every photo a
recent iPhone takes is HEVC-coded HEIF, and the libheif that ships inside sharp is built without the
decoder for it — so a HEIC reads its own header fine and then fails on the pixels, looking exactly
like a corrupt file. av-club routes those through ImageMagick, which links the system libheif and can
decode them, and hands sharp a lossless PNG. You do not have to know any of that; it just opens.
`max_dimension` shrinks so neither side is larger than the number, keeping the aspect ratio, and never
enlarges a small image. Leave it on `original` to convert without resizing.
Skips a file already in the target format, and never overwrites an existing output.
Quality is 82 for jpeg and webp and 55 for avif — the point where a photograph stops getting visibly
better and only gets bigger. EXIF orientation is applied, so a photo taken sideways comes out upright
rather than rotated.