tinieR Update

[This article was first published on R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Developing my first R package, tinieR was one of the most rewarding projects I’ve done this summer (and I’ve been busy). So much so that I couldn’t stop tinkering with it; and so now here’s tinieR 0.2.0, with added resize ability and more choice in how it returns the newly tinified file path!

Resizing

You can now use the resize argument to change the image dimensions along with its file size. I recommend reading the TinyPNG API documentation on resizing methods first, to familiarise yourself with the various options you can use to change image dimensions.

resize takes a named list, containing a method string and at least one of width or height, or both width AND height depending on your chosen resize method, to specify the dimensions in pixels you would like the image resized:

tinify("imgs/example.png", resize = list(method = "fit", width = 300, height = 150))

This should work fine alongside all existing options, like overwrite.

New return_path options

Instead of just returning the absolute file path of the newly tinified file, you can now choose to have it returned as an absolute file path, a relative file path, or a list of the two!

Set to return_path = "abs" to return the absolute file path to the tinified file as before. Set to return_path = "rel" to return the file path relative to the working directory at the time the file was tinified. This may be useful if sharing a script with others across platforms, if you can be sure your project setups will be the same and you are being strict with working directories!

Finally, set to return_path = "all" to return both types of file path as a named list:

shrunk_img_list <- tinify("imgs/example.png", return_path = "all")

knitr::include_graphics(shrunk_img_list$absolute)

I hope these new options are useful - they at least seemed like things I wanted when I was using the package myself! You can see full details at the tinieR package Github repo where the update is available for download now ????

To leave a comment for the author, please follow the link and comment on their blog: R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)