Skip to content

Conversation

@gocanto
Copy link
Collaborator

@gocanto gocanto commented Oct 10, 2025

Summary

  • register the WebP decoder so remote WebP cover images can be processed
  • add a regression test ensuring Fetch handles WebP payloads correctly

Testing

  • go test ./...

https://chatgpt.com/codex/tasks/task_e_68e8ab5a80988333bfde388849daa648

Summary by CodeRabbit

  • New Features
    • Added AVIF decoding and WebP saving support.
    • Improved remote image compatibility: handles Brotli, gzip, zstd, and malformed/embedded image data.
  • Improvements
    • More robust HTTP(S) and local file handling with better content negotiation.
    • Enhanced decoding fallbacks to successfully process non-standard image responses.
  • Bug Fixes
    • Correctly decodes images with leading noise or embedded after HTML.
  • CLI
    • Added detailed diagnostics for image decode failures to aid troubleshooting.

@gocanto gocanto marked this pull request as draft October 10, 2025 06:55
@gemini-code-assist
Copy link

Summary of Changes

Hello @gocanto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces support for WebP images, primarily targeting SEO post images. By integrating the WebP decoder and adding a comprehensive test case, the system can now correctly fetch and process WebP formatted images, which can lead to improved performance and SEO benefits. The changes ensure robust handling of WebP assets within the existing image processing infrastructure.

Highlights

  • WebP Decoder Registration: The WebP image decoder has been registered by importing the golang.org/x/image/webp package, enabling the application to process remote WebP cover images.
  • WebP Regression Test: A new regression test, TestFetchRemoteWebP, has been added to ensure that the Fetch function correctly handles and decodes WebP payloads from remote sources.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Oct 10, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a robust image fetching/decoding pipeline with multi-encoding handling, AVIF/WebP support, diagnostics surfacing, and HTTP request adjustments. Introduces a DecodeError type with diagnostics, utilities/constants for images, expanded Save to WebP, and extensive tests. Updates go.mod to add direct x/image and new indirect deps for formats/VM.

Changes

Cohort / File(s) Summary
Dependencies
go.mod
Moves golang.org/x/image v0.31.0 to direct require; adds indirect deps: github.com/andybalholm/brotli, github.com/chai2010/webp, github.com/gen2brain/avif, github.com/tetratelabs/wazero.
CLI diagnostics
metal/cli/seo/pictures.go
Prints decode diagnostics on fetch errors when error is *pkgimages.DecodeError (header + per-line details), then returns the original error.
Images support types/utilities
pkg/images/errors.go, pkg/images/globals.go
Adds DecodeError with unwrap, formatted message, and Diagnostics(); adds DefaultJPEGQuality, accept-header and UA constants, and I/O closer helpers.
Image fetch/decode core
pkg/images/image.go
Reworks Fetch with queued/deduped requests, content-encoding handling (br/gzip/zstd/identity), size-limited payload read, multi-strategy decode (std, AVIF, decompress, trim, embedded start), GitHub attachment fallbacks, AVIF/WebP support, Save to WebP, and numerous helpers.
Tests
pkg/images/image_test.go
Adds comprehensive tests for fetch/decoding across formats/encodings, AVIF fixture, GitHub fallback, headers validation, error diagnostics, and WebP save round-trip.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as CLI Caller
  participant IMG as images.Fetch
  participant SRC as openSource
  participant NET as HTTP/File
  participant DEC as Decoders
  participant Fallback as GitHub Fallback

  CLI->>IMG: Fetch(url or path)
  IMG->>SRC: Resolve source
  SRC->>NET: GET / open file (Accept + UA + encodings)
  NET-->>SRC: Response (body, Content-Type, Content-Encoding)
  SRC-->>IMG: Readable body (+wrapHTTPBody for encoding)
  IMG->>IMG: readLimited(payload, size cap)

  alt Decode succeeds
    IMG->>DEC: Try standard decode
    DEC-->>IMG: image.Image
    IMG-->>CLI: image + mime/ext
  else Decode fails
    IMG->>DEC: Try AVIF decode
    alt AVIF ok
      DEC-->>IMG: image.Image
      IMG-->>CLI: image
    else
      IMG->>IMG: Try decompress (br/gzip/zstd/zlib)
      IMG->>IMG: Trim noise / find embedded start
      IMG->>DEC: Retry decode(s)
      alt Still fails
        IMG->>Fallback: githubAttachmentFallbacks (AVIF→PNG, etc.)
        alt Fallback ok
          Fallback-->>IMG: Decodable payload
          IMG->>DEC: Decode
          DEC-->>IMG: image.Image
          IMG-->>CLI: image
        else Fallback fails
          IMG-->>CLI: error (*DecodeError with diagnostics)
        end
      else Decode ok
        DEC-->>IMG: image.Image
        IMG-->>CLI: image
      end
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

I nibbled bytes from distant streams,
Unwrapped their coats of br, gz dreams.
AVIF to PNG I hop,
WebP saved—thump, don’t stop!
When decodes fail, I leave a trail—
Diagnostics crisp as kale.
Hare today, image prevails! 🐇🖼️

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gocanto/fix-image-preparation-error-for-post-2025-10-10

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5228587 and 7048ae6.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • go.mod (4 hunks)
  • metal/cli/seo/pictures.go (2 hunks)
  • pkg/images/errors.go (1 hunks)
  • pkg/images/globals.go (1 hunks)
  • pkg/images/image.go (6 hunks)
  • pkg/images/image_test.go (5 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly adds WebP image support by registering the WebP decoder. A new regression test is included to verify that remote WebP images can be fetched and decoded. My review includes suggestions to improve the new test's robustness and maintainability by refining error handling within the test's HTTP handler and by externalizing test data.

@gocanto gocanto changed the title Add WebP support for SEO post images fix: WebP support for SEO post images Oct 10, 2025
@gocanto gocanto added testing and removed codex labels Oct 13, 2025
@gocanto gocanto marked this pull request as ready for review October 13, 2025 04:41
@gocanto gocanto merged commit ac7e123 into main Oct 13, 2025
3 checks passed
@gocanto gocanto deleted the gocanto/fix-image-preparation-error-for-post-2025-10-10 branch October 13, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants