You can change the defaults for
tinify()
using tinify_defaults()
.
tinify_defaults()
takes all the same arguments as
tinify()
except file
and key
.
Any arguments set in tinify_defaults()
will apply to all
subsequent calls of tinify()
:
tinify("example.png")
#> Filesize reduced by 50%:
#> example.png (20K) => example_tiny.png (10K)
#> 13 Tinify API calls this month
tinify_defaults(suffix = "_small")
#> Tinify 'suffix' changed to: "_small"
tinify("example2.png")
#> Filesize reduced by 50%:
#> example2.png (20K) => example2_small.png (10K)
#> 14 Tinify API calls this month
Setting the defaults, and in particular return_path
,
lets you use easily use tinify()
in other image functions
that take a string as the image file path to automatically shrink,
resize, and insert images throughout your document:
tinify_defaults(suffix = "_resized",
quiet = TRUE,
return_path = "proj",
resize = list(method = "scale",
width = 100))
#> Tinify 'suffix' changed to: "_resized"
#> Tinify 'quiet' changed to: TRUE
#> Tinify 'return_path' changed to: "proj"
#> Tinify 'resize' method changed to: "scale"
#> Tinify 'resize' width changed to: 100
knitr::include_graphics(tinify("imgs/example1.png"))
knitr::include_graphics(tinify("imgs/example2.png"))
To see all the current defaults set, call
tinify_defaults()
without any arguments:
Any arguments supplied directly to tinify()
will
always overrule any default options:
tinify_defaults(suffix = "_small")
#> Tinify 'suffix' changed to: "_small"
tinify("example2.png", suffix = "_shrunk")
#> Filesize reduced by 50%:
#> example2.png (20K) => example2_shrunk.png (10K)
#> 15 Tinify API calls this month
tinify("example3.png")
#> Filesize reduced by 50%:
#> example2.png (20K) => example2_small.png (10K)
#> 16 Tinify API calls this month
If you use Rstudio projects and would like to set the defaults for an
entire project, you could also include a tinify.yml
file in
your project directory with your desired default options:
If tinify.yml
is present in your project directory,
these options will be detected and set as the defaults when you load
tinieR with library(tinieR)
or using tinieR::
.
Note: these will not change any options previously set manually
using options()
prior to loading tinieR.
Once loaded, these options can still be changed with
tinify_defaults()
or overruled by providing arguments in
tinify()
as normal, if required.
The options quiet
and overwrite
only accept
TRUE
or FALSE
as their settings. If you change
one of these and wish to change it back, just set it again with the
opposite option:
For suffix
, you must enter a character string as an
option. If you change suffix
and wish to set it back to the
default, just set it again as "_tiny"
:
If you set defaults for either return_path
or
resize
and wish to switch these options back off again,
just set them to NULL
:
Finally, if you unload the tinieR package, you will also clear any
default options currently set. If you then reload the package, tinieR
will try and load any defaults from tinify.yml
if present,
then default to the package default settings.