Add classify, thumb_hash, perceptual_hash, crop_objects and preserve_hdr support - #93
Open
11bit wants to merge 5 commits into
Open
Add classify, thumb_hash, perceptual_hash, crop_objects and preserve_hdr support#9311bit wants to merge 5 commits into
11bit wants to merge 5 commits into
Conversation
…hdr support Covers the imgproxy Usage docs update from issue #82. Image info options: classify (cl), thumb_hash (th) and perceptual_hash (phash, ph). Processing options: crop_objects (PRO) and preserve_hdr (ph). The docs list `co` as the short keyword of crop_objects, but `co` is already the short keyword of the contrast option, so only the full `crop_objects` keyword is supported. The emitted segment is still `co:`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WQMVmChgR1GbXkCdrkFS4S
The imgproxy docs listed `co` as the short keyword of `crop_objects`, which collided with the `contrast` option. Upstream resolved it by renaming the keyword to `c_obj`, so accept both `crop_objects` and `c_obj`, and emit `c_obj:` instead of `co:`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WQMVmChgR1GbXkCdrkFS4S
Reusing a keyword across the processing and image info namespaces is an established imgproxy convention: `a` means adjust or alpha, `s` means size or file size, and `f` means output format or detected format, depending on the URL kind. `ph` is no different, and neither `size` nor `format` warns about its counterpart, so the notes were inconsistent noise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WQMVmChgR1GbXkCdrkFS4S
Both options called .join(":") on whatever was passed, so a vanilla-JS
consumer passing `class_names: "face"` got a raw `TypeError: class_names.join
is not a function` instead of the library's guard-style error.
guardIsNotArray can't be used as-is here: it rejects empty arrays, and an
empty class_names is meaningful — it behaves like an omitted one, meaning
all detected classes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WQMVmChgR1GbXkCdrkFS4S
Replaces the hand-rolled Array.isArray checks in crop_objects and classify with the shared guard, so the message goes through getParamName like every other array option. guardIsNotArray gains an optional allowEmpty flag, matching the shape of guardIsNotStr's isHex flag. It defaults to off, so the eight existing call sites keep rejecting empty arrays; only the two optional class_names lists opt in, since an empty one means "all detected classes". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WQMVmChgR1GbXkCdrkFS4S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #82
Closes #94
Upstream:
crop_objectsshort keyword renamedco→c_obj)Adds the five options that the Usage docs gained in those ranges.
Image info options (
generateImageInfoUrl)classify/cltop_k— required, integer >= 0. When greater than zero, imgproxy classifies the image and returns the top K classes with the highest confidence scores.class_names— optional; if given, imgproxy classifies only those classes.thumb_hash/th— boolean; returns the image's ThumbHash.perceptual_hash/phash/ph— boolean; returns the perceptual hash of the image.Processing options (
generateUrl)crop_objects/c_obj(PRO)scale_factor— required, number >= 0.1.0crops exactly to the detected objects,1.2adds 20% padding.class_names— optional; if omitted, imgproxy crops to all the detected objects.preserve_hdr/ph— boolean; overridesIMGPROXY_PRESERVE_HDR.On the
co→c_objrenameThe
crop_objectsdocs first landed withcoas the short keyword, which collided withcontrast— supporting both would have brokencontrast(itsbuildruns earlier and would throw on aCropObjectsobject) and madecounusable in theOptionstype. Upstream has since renamed the keyword toc_obj(#94), so this PR acceptscrop_objectsandc_objand emitsc_obj:.contrastkeepscoand the two now coexist:phmeansperceptual_hashin image info URLs andpreserve_hdrin processing URLs. That follows an established imgproxy convention —ais adjust or alpha,sis size or file size,fis output format or detected format — and this package already modelssandfthat way, so both keys are simply supported in their own namespace.Out of scope in those compare ranges
docs/configuration/options.mdx,docs/features/*,docs/image_formats_support.mdx,docs/image_sources/*,docs/installation.mdx,docs/memory_usage_tweaks.mdx,docs/monitoring/*— server configuration and feature manuals, not URL options.docs/cache/**,versioned_docs/**,sidebars.ts,docusaurus.config.tsandversions.json— docs-site restructuring and version snapshots.npm run lint,npm run check-types,npm run test -- --run(1237 tests) andnpm run buildall pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01WQMVmChgR1GbXkCdrkFS4S