Skip to content

feat(cli): support non-square source images in tauri icon - #15620

Merged
Legend-Master merged 10 commits into
tauri-apps:devfrom
tenderdeve:feat/15376-icon-non-square
Jul 21, 2026
Merged

Legend-Master merged 10 commits into
tauri-apps:devfrom
tenderdeve:feat/15376-icon-non-square

Conversation

@tenderdeve

Copy link
Copy Markdown
Contributor

Closes #15376.

tauri icon errored on any source whose width and height differ (Source image must be square). This adds a --fit option, modeled on the CSS object-fit property, to square a non-square source before the existing icon pipeline runs:

tauri icon brand.png --fit cover
  • cover — scale to fill the square, center-cropping the longer side (may clip content)
  • contain — scale to fit inside the square, padding the shorter side with transparency

SVG sources are rasterized at their native size before fitting (square SVGs keep their vector path unchanged). A non-square source without --fit still errors, now with a hint pointing to the flag.

Test

  • Unit tests for fit_to_square covering both modes (square output dimensions, center-crop stays opaque, contain padding is transparent).
  • Manually ran tauri icon on an 80x40 PNG: no --fit errors with the hint; --fit cover and --fit contain both produce a full square icon set (icon.png 512x512, icon.ico, etc.).

@tenderdeve
tenderdeve requested a review from a team as a code owner June 30, 2026 12:51
@Legend-Master Legend-Master added this to the 2.12 milestone Jun 30, 2026
@github-actions

github-actions Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Package Changes Through 4c348e5

There are 14 changes which include tauri with minor, tauri-cli with minor, @tauri-apps/cli with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, tauri-bundler with minor, tauri-build with minor, tauri-macos-sign with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor, @tauri-apps/api with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.11.1 2.12.0
tauri-utils 2.9.3 2.10.0
tauri-macos-sign 2.3.4 2.4.0
tauri-bundler 2.9.4 2.10.0
tauri-runtime 2.11.3 2.12.0
tauri-runtime-wry 2.11.4 2.12.0
tauri-codegen 2.6.3 2.7.0
tauri-macros 2.6.3 2.7.0
tauri-plugin 2.6.3 2.7.0
tauri-build 2.6.3 2.7.0
tauri 2.11.5 2.12.0
@tauri-apps/cli 2.11.4 2.12.0
tauri-cli 2.11.4 2.12.0
tauri-driver 2.0.6 2.1.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Comment thread crates/tauri-cli/src/icon.rs Resolved
`tauri icon` rejected any source whose width and height differ. Add a `--fit`
option, modeled on the CSS `object-fit` property, to square a non-square source
before generating icons:

- `cover`: scale to fill the square, center-cropping the longer side
- `contain`: scale to fit inside the square, padding the shorter side with transparency

SVG sources are rasterized at their native size before fitting. Non-square
sources without `--fit` still error, now with a hint pointing to the flag.

closes tauri-apps#15376
@tenderdeve
tenderdeve force-pushed the feat/15376-icon-non-square branch from 82be280 to 5b7b424 Compare July 9, 2026 07:29
@tenderdeve

Copy link
Copy Markdown
Contributor Author

@Legend-Master good catch. rasterize_svg now scales the longest side up to a 1024px floor before rasterizing (upscale-only — sources already larger are left as-is). Since SVG is vector this is lossless, so a small width attribute no longer produces a tiny raster that the later icon sizes have to upscale from. Signed + cargo check/fmt clean.

Comment thread crates/tauri-cli/src/icon.rs Resolved
@Legend-Master Legend-Master added the status: waiting Waiting on author label Jul 16, 2026
Keep SVG sources as a vector tree through the fit step and apply the
crop/pad as a transform when rendering each target size, instead of
rasterizing once at a fixed floor and squaring the bitmap. Icons are now
rendered directly from the vector at their final resolution, so a source
with a small intrinsic size stays crisp and the MIN_SVG_RASTER_SIZE
upscale hack is gone.
@Legend-Master Legend-Master removed the status: waiting Waiting on author label Jul 21, 2026
Legend-Master
Legend-Master previously approved these changes Jul 21, 2026

@Legend-Master Legend-Master 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.

Awesome, thanks!

@Legend-Master
Legend-Master merged commit 0646cc1 into tauri-apps:dev Jul 21, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Support non-square images in tauri icon

2 participants