feat(logo): add stamp_logo_png() for branding file-based (PNG) outputs #9

Merged
jared merged 1 commits from feat/stamp-logo-png into master 2026-06-22 16:59:53 -04:00
Owner

Summary

Adds stamp_logo_png() — the raster analogue of civilytics_logo() for outputs that are already rendered to a file rather than held as a ggplot/grob.

civilytics_logo() / make_logo_grob() brand ggplot objects, but flextables and other table outputs are exported to PNG first, so they can't be branded with the existing helpers (they currently get hand-rolled, package-external logo compositing). stamp_logo_png() closes that gap: it resolves the same brand asset that make_logo_grob() selects (same type/variant switch) and composites it into a corner of an existing PNG in place — so file-based tables stay visually consistent with logo-branded plots.

Design

  • Dependency-free. Uses only png + grid + grDevices, all already in Imports — deliberately no magick dependency for the package.
  • Preserves the image's pixel dimensions (overwrites in place).
  • Configurable type (wordmark/mark), variant (light/dark), position (four corners), width_frac, margin_frac. Defaults match civilytics_logo() (wordmark / light / bottom-right).
# Brand a table exported to PNG so it matches civilytics_logo()-branded plots
ragg::agg_png("table.png", width = 8, height = 4, units = "in", res = 200)
plot(flextable::flextable(head(mtcars)))
dev.off()
stamp_logo_png("table.png")                                   # wordmark, bottom-right
stamp_logo_png("table.png", type = "mark", position = "bottom-left")

Tests

tests/testthat/test_logo.R (21 assertions): dimension preservation + invisible path return, all 16 type/variant/position combinations run, and input validation (missing file, invalid type). All pass.

Notes

  • Docs regenerated for this function only (man/stamp_logo_png.Rd + the relevant NAMESPACE exports/imports). I intentionally did not sweep up the pre-existing roxygen drift in master (unrelated .Rd/NAMESPACE churn) to keep this PR focused.
  • Origin: extracted from the CRDC social-media reporting pipeline, where six branded table chunks each hand-rolled this compositing; this generalizes it into the brand package so any flextable/PNG output can brand consistently.

🤖 Generated with Claude Code

## Summary Adds `stamp_logo_png()` — the raster analogue of `civilytics_logo()` for outputs that are already rendered to a file rather than held as a ggplot/grob. `civilytics_logo()` / `make_logo_grob()` brand ggplot objects, but **flextables and other table outputs are exported to PNG first**, so they can't be branded with the existing helpers (they currently get hand-rolled, package-external logo compositing). `stamp_logo_png()` closes that gap: it resolves the **same brand asset** that `make_logo_grob()` selects (same `type`/`variant` switch) and composites it into a corner of an existing PNG in place — so file-based tables stay visually consistent with logo-branded plots. ## Design - **Dependency-free.** Uses only `png` + `grid` + `grDevices`, all already in `Imports` — deliberately **no `magick`** dependency for the package. - Preserves the image's pixel dimensions (overwrites in place). - Configurable `type` (wordmark/mark), `variant` (light/dark), `position` (four corners), `width_frac`, `margin_frac`. Defaults match `civilytics_logo()` (wordmark / light / bottom-right). ```r # Brand a table exported to PNG so it matches civilytics_logo()-branded plots ragg::agg_png("table.png", width = 8, height = 4, units = "in", res = 200) plot(flextable::flextable(head(mtcars))) dev.off() stamp_logo_png("table.png") # wordmark, bottom-right stamp_logo_png("table.png", type = "mark", position = "bottom-left") ``` ## Tests `tests/testthat/test_logo.R` (21 assertions): dimension preservation + invisible path return, all 16 type/variant/position combinations run, and input validation (missing file, invalid `type`). All pass. ## Notes - Docs regenerated for this function only (`man/stamp_logo_png.Rd` + the relevant `NAMESPACE` exports/imports). I intentionally did **not** sweep up the pre-existing roxygen drift in `master` (unrelated `.Rd`/`NAMESPACE` churn) to keep this PR focused. - Origin: extracted from the CRDC social-media reporting pipeline, where six branded table chunks each hand-rolled this compositing; this generalizes it into the brand package so any flextable/PNG output can brand consistently. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-06-22 16:36:07 -04:00
feat(logo): add stamp_logo_png() to brand file-based PNG outputs
R-CMD-check / R CMD check (pull_request) Successful in 3m53s
5fc8155965
civilytics_logo()/make_logo_grob() brand ggplot/grobs, but flextables and
other outputs are rendered to PNG first and can't use them. stamp_logo_png()
is the raster analogue: it resolves the SAME brand asset that make_logo_grob()
uses (via the type/variant switch) and composites it into a corner of an
existing PNG in place, so file-based tables stay visually consistent with
logo-branded plots.

Dependency-free by design — uses only png + grid + grDevices (all already
imported), no magick. Configurable type/variant/position/width/margin;
preserves the image's pixel dimensions. Adds tests (21 assertions).
jared merged commit 761a72da18 into master 2026-06-22 16:59:53 -04:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Civilytics/civilyticsR#9