feat(logo): add stamp_logo_png() to brand file-based PNG outputs
R-CMD-check / R CMD check (pull_request) Successful in 3m53s
R-CMD-check / R CMD check (pull_request) Successful in 3m53s
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).
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/logo.R
|
||||
\name{stamp_logo_png}
|
||||
\alias{stamp_logo_png}
|
||||
\title{Stamp the Civilytics logo onto a saved raster (PNG) image}
|
||||
\usage{
|
||||
stamp_logo_png(
|
||||
path,
|
||||
type = c("wordmark", "mark"),
|
||||
variant = c("light", "dark"),
|
||||
position = c("bottom-right", "bottom-left", "top-right", "top-left"),
|
||||
width_frac = 0.15,
|
||||
margin_frac = 0.02
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{path}{Character. Path to the PNG to stamp. The file is overwritten
|
||||
in place at its original pixel dimensions.}
|
||||
|
||||
\item{type}{Character. `"wordmark"` (default) or `"mark"`. As in
|
||||
[make_logo_grob()].}
|
||||
|
||||
\item{variant}{Character. `"light"` (default, dark logo for light
|
||||
backgrounds) or `"dark"` (reverse logo for dark backgrounds).}
|
||||
|
||||
\item{position}{Character. Corner placement: `"bottom-right"` (default),
|
||||
`"bottom-left"`, `"top-right"`, or `"top-left"`.}
|
||||
|
||||
\item{width_frac}{Numeric. Logo width as a fraction of the image width
|
||||
(default `0.15`). Height follows from the logo's aspect ratio.}
|
||||
|
||||
\item{margin_frac}{Numeric. Padding from the edges as a fraction of the
|
||||
image width (default `0.02`).}
|
||||
}
|
||||
\value{
|
||||
`path`, invisibly.
|
||||
}
|
||||
\description{
|
||||
The raster analogue of [civilytics_logo()] for outputs that are already
|
||||
rendered to a file rather than held as a ggplot/grob — e.g. a `flextable`
|
||||
exported to PNG, or any `grDevices::png()` / `ragg::agg_png()` output.
|
||||
Resolves the *same* brand asset that [make_logo_grob()] uses, so file-based
|
||||
tables stay visually consistent with logo-branded plots, and composites it
|
||||
into a corner of the image. Pure base-graphics + grid + png — no new
|
||||
package dependencies.
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
# 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user