Skip to content

Dev: Webpを画像形式に追加 - #2981

Open
noponoponopo wants to merge 3 commits into
traPtitech:masterfrom
noponoponopo:dev/addWebpToStampImageTypes
Open

Dev: Webpを画像形式に追加#2981
noponoponopo wants to merge 3 commits into
traPtitech:masterfrom
noponoponopo:dev/addWebpToStampImageTypes

Conversation

@noponoponopo

@noponoponopo noponoponopo commented Apr 13, 2026

Copy link
Copy Markdown

スタンプとしてWebpを追加できるように変更

Summary by CodeRabbit

  • New Features
    • Added support for uploading and displaying static WebP images across stamps, icons, and image responses.
    • WebP images are resized and preserved in WebP format during processing.
    • Animated WebP images are rejected as unsupported.
    • Improved handling of invalid PNG and JPEG uploads.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The image upload pipeline now supports still WebP images. It rejects animated WebP images, resizes and re-encodes valid WebP images, records WebP metadata, and updates the API specification for WebP uploads and responses.

Changes

WebP image processing

Layer / File(s) Summary
MIME contract and processing
router/consts/mime_types.go, router/utils/process_image.go, go.mod
Adds the MimeImageWebP constant and the nativewebp dependency. WebP uploads are validated, animated images are rejected, and valid images are resized and encoded as WebP.
API specification
docs/v3-api.yaml
Documents WebP support for stamp, user-group, webhook, user, bot, and public icon uploads and responses.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ImagePipeline
  participant nativewebp
  participant ImageResizer
  participant WebPEncoder
  Client->>ImagePipeline: upload WebP image
  ImagePipeline->>nativewebp: detect and validate image
  nativewebp-->>ImagePipeline: validation result
  ImagePipeline->>ImageResizer: resize valid image
  ImageResizer-->>ImagePipeline: resized image
  ImagePipeline->>WebPEncoder: encode resized image
  WebPEncoder-->>ImagePipeline: WebP data and metadata
  ImagePipeline-->>Client: upload result
Loading

Suggested reviewers: otukado

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding WebP as a supported image format.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch dev/addWebpToStampImageTypes
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@router/utils/process_image.go`:
- Line 85: The new case for consts.MimeImageWebP in saveUploadImage
unintentionally enables WebP for icons because saveUploadImage is called by
SaveUploadIconImage and SaveUploadStampImage; restrict the WebP handling to
stamps only by conditioning that branch on fType == model.FileTypeStamp (check
the fType parameter inside saveUploadImage before executing the WebP-specific
logic) so icons remain unchanged while stamps gain WebP support.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 142d627f-23d3-49fa-9f61-8c9b4074e942

📥 Commits

Reviewing files that changed from the base of the PR and between 1ebbfab and 85c0799.

📒 Files selected for processing (2)
  • router/consts/mime_types.go
  • router/utils/process_image.go

args.MimeType = consts.MimeImagePNG
args.Thumbnail = img // サムネイル画像より小さいという前提

case consts.MimeImageWebP:

@coderabbitai coderabbitai Bot Apr 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

This also enables WebP uploads for icons.

saveUploadImage is used by both SaveUploadIconImage (Lines 28-29) and SaveUploadStampImage (Lines 33-34), so adding the MimeImageWebP case here widens icon uploads too. The PR objective is stamp-only, so gate this branch on fType == model.FileTypeStamp if icons are not meant to change.

💡 Narrow WebP support to stamps only
 case consts.MimeImageWebP:
+	if fType != model.FileTypeStamp {
+		return uuid.Nil, herror.BadRequest(badImage)
+	}
 	isAnimated, _ := midec.IsAnimated(src)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case consts.MimeImageWebP:
case consts.MimeImageWebP:
if fType != model.FileTypeStamp {
return uuid.Nil, herror.BadRequest(badImage)
}
isAnimated, _ := midec.IsAnimated(src)
// ... rest of WebP handling code continues below
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router/utils/process_image.go` at line 85, The new case for
consts.MimeImageWebP in saveUploadImage unintentionally enables WebP for icons
because saveUploadImage is called by SaveUploadIconImage and
SaveUploadStampImage; restrict the WebP handling to stamps only by conditioning
that branch on fType == model.FileTypeStamp (check the fType parameter inside
saveUploadImage before executing the WebP-specific logic) so icons remain
unchanged while stamps gain WebP support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

まぁ icon まで認めてしまっていいんじゃないか? PR のタイトルは変えた方がいいかも

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Takeno-hito、ご判断ありがとうございます!アイコンにも WebP を許可する方針であれば、現在の実装のままで問題ありません。PR タイトルを「スタンプの画像形式にWebpを追加」から「スタンプ・アイコンの画像形式にWebpを追加」のように変更すると、変更内容が正確に伝わりますね。

( ˶ᵔ ᵕ ᵔ˶ )

@Takeno-hito Takeno-hito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ぱぱっとコメント付けたので確認頂きたいです…! 動作確認はできてないので他の人頼んだ!!

Comment thread router/utils/process_image.go Outdated
"io"

"github.com/sapphi-red/midec"
_ "github.com/sapphi-red/midec/webp"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

blank import になってるけどこれは理由がある?なければ削除してほしい

Comment thread router/utils/process_image.go Outdated
"io"

"github.com/sapphi-red/midec"
_ "github.com/sapphi-red/midec/webp"

@Takeno-hito Takeno-hito Apr 13, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

import が sort されていなさそう(どちらかというと linter が落ちないのが悪い気がするが)

Comment thread router/utils/process_image.go Outdated
args.Thumbnail = img // サムネイル画像より小さいという前提

case consts.MimeImageWebP:
isAnimated, _ := midec.IsAnimated(src)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MUST: err ハンドリングをしてほしい

isAnimated, err := mide.IsAnimated(src)
if err != nil {
    return uuid.Nil, herror.InternalServerError(err)
}

Comment thread router/utils/process_image.go Outdated
img, err := p.Fit(src, maxImageSize, maxImageSize)
if err != nil {
switch err {
case imaging.ErrInvalidImageSrc:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

errors.Is を使ってほしいかも?
errors.Is(err, imaging.ErrInvalidImageSrc) という形

return uuid.Nil, herror.InternalServerError(seekErr)
}
if isAnimated {
return uuid.Nil, herror.BadRequest("animated WebP is not supported")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

want: アイコンもスタンプも animation 対応できるので、 TODO コメントを付けるかアニメーションも対応できるかどっちかはしてほしいかも!例えば

// TODO: アニメーションの WebP 対応 

とか

Comment thread router/utils/process_image.go Outdated

case consts.MimeImageWebP:
isAnimated, _ := midec.IsAnimated(src)
if _, seekErr := src.Seek(0, io.SeekStart); seekErr != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seekErr => err

Comment thread router/utils/process_image.go Outdated
args.Thumbnail = img // サムネイル画像より小さいという前提

case consts.MimeImageWebP:
isAnimated, _ := midec.IsAnimated(src)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

comment: isAnimated ですが、後続の 90 行目で判定をしているので、この isAnimated の宣言をもう少し後ろに置くと見やすいコードになると思います!

つまり、

seekErr チェック → isAnimated → err チェック → if isAnimated の順

Comment thread router/utils/process_image.go Outdated
return uuid.Nil, herror.InternalServerError(err)
}
}
b := bytes.Buffer{}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nits: (好みの問題です) 個人的には、 var b bytes.Buffer という形で宣言してある方がちょっと見やすいかも

args.MimeType = consts.MimeImagePNG
args.Thumbnail = img // サムネイル画像より小さいという前提

case consts.MimeImageWebP:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

まぁ icon まで認めてしまっていいんじゃないか? PR のタイトルは変えた方がいいかも

@noponoponopo
noponoponopo requested a review from a team as a code owner August 11, 2026 15:23
@noponoponopo noponoponopo changed the title Dev: Webpをスタンプの画像形式に追加 Dev: Webpを画像形式に追加 Aug 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@router/utils/process_image.go`:
- Around line 99-117: Update SaveUploadIconImage, SaveUploadStampImage, and
saveUploadImage to accept context.Context as their first parameter and propagate
it through the call chain to m.Save. Before and after each context-unaware call,
including midec.IsAnimated, p.Fit, and nativewebp.Encode, check ctx.Err() and
return the cancellation error when the context is done.
- Around line 10-13: Add the blank import for github.com/sapphi-red/midec/webp
alongside the existing midec imports so the WebP detector is registered before
midec.IsAnimated runs. Add coverage for both static and animated WebP inputs,
ensuring valid files are not reported as bad image.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ab5ad76-eff1-4199-b70e-6da3ae8a7ab2

📥 Commits

Reviewing files that changed from the base of the PR and between 85c0799 and ec8b2e1.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • docs/v3-api.yaml
  • go.mod
  • router/utils/process_image.go

Comment on lines +10 to +13
"github.com/HugoSmits86/nativewebp"
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/sapphi-red/midec"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Expect: the application imports the WebP detector or registers it explicitly.
rg -n --glob '*.go' \
  'github\.com/sapphi-red/midec/webp|midec\.RegisterFormat' .

Repository: traPtitech/traQ

Length of output: 2043


🌐 Web query:

github sapphi-red/midec v0.5.2 IsAnimated webp registration ErrFormat

💡 Result:

The midec package (version v0.5.2) is a Go library designed to detect if an image file is a multi-image or animated format [1][2]. The error ErrFormat is a standard error defined in the Go image package [3], which is often used in Go imaging libraries to signal that a file's format is unknown or unsupported [3]. In the context of midec: 1. Format Registration: midec uses a registration system modeled after the standard image.RegisterFormat function [1][2]. To detect specific formats like Animated WebP, you must import the corresponding sub-package to register it [1]. 2. Usage: For example, to support Animated WebP, you should include _ "github.com/sapphi-red/midec/webp" in your imports [1]. 3. ErrFormat: If you receive an ErrFormat (or encounter issues during detection), it typically indicates that the provided io.Reader does not match any registered format's "magic header" [3]. If you have not explicitly imported the sub-package for the specific format (e.g., WebP), the library will not recognize the header, resulting in a failure to detect it as an animated image [1]. Ensure that you have imported the midec/webp package in your main or init function to ensure the Animated WebP format is registered before calling midec.IsAnimated [1].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

for url in \
  https://raw.githubusercontent.com/traPtitech/traQ/master/router/utils/process_image.go \
  https://raw.githubusercontent.com/traPtitech/traQ/main/router/utils/process_image.go \
  https://raw.githubusercontent.com/sapphi-red/midec/v0.5.2/midec.go \
  https://raw.githubusercontent.com/sapphi-red/midec/v0.5.2/webp/webp.go \
  https://raw.githubusercontent.com/sapphi-red/midec/v0.5.2/go.mod
do
  echo "=== $url ==="
  curl -fsSL "$url" || true
  echo
done

Repository: traPtitech/traQ

Length of output: 2014


🌐 Web query:

site:github.com/traPtitech/traQ "router/utils/process_image.go" "midec.IsAnimated"

💡 Result:

In the traPtitech/traQ codebase, midec.IsAnimated is a function used within router/utils/process_image.go to detect whether an image (specifically WebP) is animated [1]. The integration of this check is part of the image upload pipeline [1]. When processing images—particularly when adding support for formats like WebP—the application uses midec.IsAnimated to validate the uploaded file [1]. If the image is determined to be animated, the system rejects it (typically returning a BadRequest error) to prevent the storage of animated files where they are not supported, such as in certain stamp or image upload contexts [1]. The midec package itself (likely referencing a library like github.com/sapphi-red/midec, as indicated by the project's go.mod) provides these utility functions for MIME type detection and image property analysis [1][2]. Within router/utils/process_image.go, this check ensures that only static images are processed and accepted into the relevant parts of the application's storage system [1].

Citations:


🌐 Web query:

site:github.com/sapphi-red/midec/blob/v0.5.2 "package webp" "RegisterFormat"

💡 Result:

Found it: webp/reader.go in sapphi-red/midec at tag v0.5.2.

The relevant code is:

// Package webp implements a Animated WebP detector
package webp
...
func init() {
    midec.RegisterFormat("webp", webpHeader, isAnimated)
}

Source: [1] (github.com)

Citations:


Register the WebP detector before calling midec.IsAnimated.

Without _ "github.com/sapphi-red/midec/webp", midec.IsAnimated returns midec.ErrFormat for WebP input. This path then reports valid WebP uploads as bad image.

Add the blank import and test static and animated WebP files.

Proposed fix
 	"github.com/sapphi-red/midec"
+	_ "github.com/sapphi-red/midec/webp"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"github.com/HugoSmits86/nativewebp"
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/sapphi-red/midec"
"github.com/HugoSmits86/nativewebp"
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/sapphi-red/midec"
_ "github.com/sapphi-red/midec/webp"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@router/utils/process_image.go` around lines 10 - 13, Add the blank import for
github.com/sapphi-red/midec/webp alongside the existing midec imports so the
WebP detector is registered before midec.IsAnimated runs. Add coverage for both
static and animated WebP inputs, ensuring valid files are not reported as bad
image.

Comment on lines +99 to +117
img, err := p.Fit(src, maxImageSize, maxImageSize)
if err != nil {
switch {
case errors.Is(err, imaging.ErrInvalidImageSrc):
return uuid.Nil, herror.BadRequest(badImage)
case err == imaging.ErrPixelLimitExceeded:
return uuid.Nil, herror.BadRequest(tooLargeImage)
default:
return uuid.Nil, herror.InternalServerError(err)
}
}
var b bytes.Buffer
if err := nativewebp.Encode(&b, img, nil); err != nil {
return uuid.Nil, herror.InternalServerError(err)
}
args.Src = bytes.NewReader(b.Bytes())
args.FileSize = int64(b.Len())
args.MimeType = consts.MimeImageWebP
args.Thumbnail = img

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Inspect all wrappers, helper calls, and imaging processor contracts.
rg -n --glob '*.go' \
  'SaveUploadIconImage|SaveUploadStampImage|saveUploadImage|type Processor interface|func .*Fit\(|\.Fit\(' \
  router service

Repository: traPtitech/traQ

Length of output: 2043


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- candidate files ---'
git ls-files | rg '(^|/)(process_image\.go|.*_test\.go|go\.mod)$' | head -200

printf '%s\n' '--- target file ---'
if [ -f router/utils/process_image.go ]; then
  cat -n router/utils/process_image.go
else
  printf '%s\n' 'router/utils/process_image.go not present'
fi

printf '%s\n' '--- related call sites and declarations ---'
rg -n --glob '*.go' \
  'SaveUploadIconImage|SaveUploadStampImage|saveUploadImage|type Processor interface|func .*Fit\(|\.Fit\(|midec\.IsAnimated|nativewebp\.Encode|\.Save\(' \
  . | head -400

printf '%s\n' '--- module declarations ---'
if [ -f go.mod ]; then
  rg -n 'imaging|midec|webp' go.mod go.sum
fi

Repository: traPtitech/traQ

Length of output: 2014


🌐 Web query:

traPtitech traQ router/utils/process_image.go SaveUploadIconImage saveUploadImage

💡 Result:

In the traQ backend repository (traPtitech/traQ), the file router/utils/process_image.go contains image processing logic, including the function saveUploadImage [1][2]. This function is used by higher-level handlers such as SaveUploadIconImage (for user icons) and others (e.g., for stamps) to process and store uploaded image files [1]. Recent developments in the repository indicate that saveUploadImage handles various image formats and includes validation and conversion logic [1]. For instance, a pull request (#2981) specifically modified this file to add support for WebP images, particularly for stamps [1]. The implementation details of saveUploadImage involve detecting the image MIME type, validating the content (such as rejecting unsupported animated formats), and potentially performing resizing or format conversion (e.g., converting to PNG) before saving the file [1]. When integrating new features like WebP support, developers must ensure that the logic within saveUploadImage correctly differentiates between file types—such as distinguishing between user icons and stamps—to prevent unintended side effects for image types that should remain restricted [1].

Citations:


🌐 Web query:

github.com/traPtitech/traQ imaging Processor Fit context Go

💡 Result:

In the traQ (traP Internal Messenger Application) project, "imaging" refers to the system's image processing functionality, which utilizes the third-party Go package github.com/disintegration/imaging [1][2]. The term "Fit" is a specific function provided by the imaging package [1]. Contextual details regarding their usage in traQ: 1. Imaging Processor: traQ uses the disintegration/imaging library for image handling, such as resizing, cropping, and converting uploaded images (e.g., icons or stamps) [3][2]. The application includes configuration options for this processing, such as maxPixels (to prevent excessive memory usage) and concurrency (to control CPU/memory usage for image tasks) [4]. 2. Fit Function: The imaging.Fit function is a specific method from the library used to resize images [1]. It scales an image down to fit within a specified bounding box (e.g., width x height) while maintaining the original aspect ratio [1]. In the context of traQ, this ensures that user-uploaded images are normalized to appropriate dimensions for the interface [3]. The imaging configuration in traQ is typically defined in config.yml, allowing administrators to tune performance based on their deployment needs [4].

Citations:


🌐 Web query:

github.com/sapphi-red/midec IsAnimated ErrFormat Go

💡 Result:

The Go library sapphi-red/midec is a multi-image detector used to determine if an image file (such as GIF, APNG, WebP, or HEIF/AVIF) is animated [1][2]. Regarding the specific terms in your query: IsAnimated: This is the primary function provided by the midec package [1][2]. It accepts an io.Reader and returns a boolean value indicating whether the input image is animated [1]. ErrFormat: This is not a component of the midec library itself, but rather a standard error variable defined in the Go standard library's image package (image.ErrFormat) [3][4]. It is commonly used in Go to indicate that an image format is unknown or not registered [3][5]. Because midec is designed to be similar to the standard image package, it may interact with or follow patterns similar to those where image.ErrFormat is used, but it is not part of the midec API [1][2]. In summary, midec provides the IsAnimated functionality to check for multi-image/animated content, while ErrFormat is a standard Go library constant for handling unknown image formats [1][3].

Citations:


🌐 Web query:

site:raw.githubusercontent.com/traPtitech/traQ process_image.go "func SaveUploadIconImage"

💡 Result:

No matching result was found for that exact query. The SaveUploadIconImage function may be on a non-default branch, in a moved file, or no longer present in the repository.


🌐 Web query:

site:github.com/traPtitech/traQ/blob/master/router/utils/process_image.go "saveUploadImage"

💡 Result:

saveUploadImage is defined in router/utils/process_image.go at line 32.

It:

  • Opens the multipart-uploaded file.
  • Enforces the configured file-size limit.
  • Accepts PNG, JPEG, and GIF.
  • Resizes images to the maximum dimensions.
  • Converts PNG/JPEG uploads to PNG.
  • Generates thumbnails for GIFs.
  • Saves the processed file through file.Manager.
  • Returns the saved file’s UUID. (raw.githubusercontent.com)

Citations:


🌐 Web query:

disintegration imaging Processor interface Fit Go context

💡 Result:

The terms in your query refer to two distinct and unrelated concepts in the Go programming ecosystem: 1. disintegration/imaging: This is a popular, lightweight Go package for image processing (e.g., resizing, cropping, rotation) [1][2][3]. It is not related to a Processor interface or Go context patterns. Its functions operate directly on types that satisfy the standard library's image.Image interface [1][4][5]. 2. Processor interface with context.Context: This is a common design pattern in Go for building extensible pipelines, workers, or middleware [6][7][8]. While not part of the standard library, it is frequently implemented using the following signature to ensure cancellation and timeout propagation [6][7][9]: type Processor interface { Process(ctx context.Context, r *Record) error } In this pattern, the context.Context is passed as the first argument to allow for graceful cancellation or deadline enforcement during the processing of a task [6][7][8]. Developers often use a functional adapter (e.g., ProcessorFunc) to allow simple functions to satisfy this interface, similar to the standard library's http.HandlerFunc [7]. If you were looking for a specific library that combines these, it is likely that you are using a custom wrapper or a different framework (such as Benthos or a background worker library) that utilizes the Processor interface pattern to handle image processing tasks or other data operations [7][8].

Citations:


🌐 Web query:

sapphi-red midec IsAnimated Go source Register WebP

💡 Result:

The sapphi-red/midec library is a pure Go multi-image (animated image) detector that supports formats such as GIF, APNG, WebP, and HEIF/AVIF [1][2]. To check if an image is animated, you use the IsAnimated function [1][2]. The usage pattern is as follows: import ( "fmt" "os" "github.com/sapphi-red/midec" _ "github.com/sapphi-red/midec/webp" // import to enable Animated WebP detection) func main { fp, _:= os.Open("image.webp") isAnimated:= midec.IsAnimated(fp) fmt.Println(isAnimated) } To add support for a new format or to register a specific handler, you use the midec.RegisterFormat function [1][2]. This function behaves similarly to the standard library's image.RegisterFormat and is typically called within an init function to register a format's header signature and its corresponding detection function [1][2]. Example: func init { midec.RegisterFormat("webp", webpHeader, isAnimated) } The library is designed with a pluggable architecture, allowing users to import specific sub-packages (e.g., _ "github.com/sapphi-red/midec/webp") to register and enable detection for that specific image format [1][2].

Citations:


🌐 Web query:

"func saveUploadImage" "imaging.Processor" traQ

💡 Result:

In the context of the traQ (traP Internal Messenger Application) backend, saveUploadImage is an internal function responsible for processing and saving uploaded images [1]. The function is typically located within the application's router utilities (e.g., router/utils/process_image.go) [1]. It manages the image upload pipeline, which includes: 1. Identification and validation of MIME types [1]. 2. Processing based on the file type (e.g., handling specific formats like WebP or standard images for stamps and icons) [1]. 3. Interaction with external image processing libraries—specifically github.com/disintegration/imaging—which is used within the traQ backend to handle image transformations [1][2]. The imaging.Processor refers to the functionality provided by the disintegration/imaging Go library, which is utilized by traQ for resizing, encoding, and other image manipulations during the upload process [1][2]. As an internal backend utility, saveUploadImage is not part of the public traQ API client library [3]. Developers looking to interact with traQ's image features should use the official API endpoints rather than attempting to call internal helper functions directly [3].

Citations:


🌐 Web query:

"SaveUploadStampImage" "context.Context" traQ

💡 Result:

In the traQ backend codebase, SaveUploadStampImage is a function responsible for handling the image processing and saving logic when a new stamp is uploaded [1]. It is not a public API endpoint, but rather an internal utility function within the server-side implementation [1]. It is often invoked in contexts where an image file needs to be processed and stored as a stamp [1]. The function receives a context.Context as an argument, which is standard practice in the traQ Go backend to handle request-scoped values, cancellations, and deadlines across asynchronous operations or service calls [2][3]. The function is closely related to other image-handling routines and has been updated in the past to support different image formats, such as WebP, specifically for stamps [1]. Because it is an internal backend function, developers interacting with the traQ system typically use the high-level API methods provided by the official SDKs (such as ChangeStampImage or CreateStamp) rather than calling SaveUploadStampImage directly [2][3]. These high-level API methods also accept a context.Context to maintain proper request management [2].

Citations:


🌐 Web query:

"midec.IsAnimated" "nativewebp.Encode" traQ

💡 Result:

The terms mentioned relate to Go-based image processing components often used in the context of the traQ messenger application or similar projects associated with Digital Creators Club traP. midec refers to a library (often seen as sapphi-red/midec or its WebAssembly port node-midec) that functions as a multi-image detector capable of identifying formats like Animated GIF, APNG, Animated WebP, and Animated HEIF/AVIF [1]. nativewebp is a pure Go implementation of a WebP encoder that does not require external C libraries like libwebp [2][3]. Within the nativewebp package, nativewebp.Encode is the primary function used to encode a single image into WebP format [2][4]. The package also supports animations through functions like EncodeAll, which handles multi-frame WebP files [2][3][5]. traQ is the open-source internal messenger application developed by the Digital Creators Club traP, written primarily in Go [6][7]. Components like image processing libraries are frequently integrated into such systems to handle media uploads and previews [6]. While these components may be used together in a software stack, there is no single standardized function named midec.IsAnimated that directly calls nativewebp.Encode in a public, monolithic API. Rather, midec is typically used to detect image characteristics, and nativewebp is used to encode/transcode them [2][1]. Developers often integrate these tools to perform tasks such as detecting animated media and subsequently re-encoding them into an optimized format like WebP [2][1][5].

Citations:


🌐 Web query:

site:github.com/traPtitech/traQ/pull/2981 process_image.go context

💡 Result:

The filename process_image.go is not a standard library component in the Go programming language, nor is it part of a universally defined framework. Instead, it is a common naming convention used by developers in specific Go-based projects to encapsulate image manipulation logic [1]. In software projects using this filename, process_image.go typically resides within utility or service directories (e.g., /router/utils/ or /internal/utils/) and is responsible for handling tasks such as: 1. Image Format Validation: Checking MIME types or file extensions to ensure the image meets project requirements [1]. 2. Processing Pipelines: Implementing logic for resizing, converting between formats (e.g., WebP to PNG), or compressing images [1]. 3. Metadata Management: Validating image properties or updating metadata during the upload or storage lifecycle [1]. 4. Error Handling: Mapping specific image processing failures (e.g., unsupported format or invalid animation) to appropriate system or HTTP responses [1]. If you have encountered this file in a specific codebase, it is a custom implementation tailored to that application's requirements for managing image assets.

Citations:


Propagate the request context through image processing.

Update SaveUploadIconImage, SaveUploadStampImage, and saveUploadImage to accept context.Context first. Pass it to m.Save, and check ctx.Err() before and after context-unaware calls such as midec.IsAnimated, p.Fit, and nativewebp.Encode.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@router/utils/process_image.go` around lines 99 - 117, Update
SaveUploadIconImage, SaveUploadStampImage, and saveUploadImage to accept
context.Context as their first parameter and propagate it through the call chain
to m.Save. Before and after each context-unaware call, including
midec.IsAnimated, p.Fit, and nativewebp.Encode, check ctx.Err() and return the
cancellation error when the context is done.

Source: Path instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants