A walkthrough of dealing with images in R and creating a custom image gallery.
While developing and designing software projects in R it is very common to have to deal with various images and the process of manipulating, re-sizing, cropping, and dealing with these images can be a huge pain and waste of time.
Some examples of the pain points when dealing with images are:
magick
PackageRecently I finally decided to take a gander into the popular magick R library.
This package is a swiss-army-knife for dealing with images in R.
A good place to start is the image_resize
function which allows you to resize the dimensions of your images. To add to that, let’s create a function allowing one to:
magick::image_read
magick::image_resize
magick::image_write
HTML Head needs:
<head>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.6.0/css/lightgallery.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery-js/1.4.1-beta.0/js/lightgallery.min.js"></script>
<!-- lightgallery plugins -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lg-fullscreen/1.2.1/lg-fullscreen.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lg-thumbnail/1.2.1/lg-thumbnail.min.js"></script>
</head>
Plus the following CSS customization:
#lightgallery > a > img:hover {
transform: scale(1.15, 1.15);
transition: 0.4s ease-in-out;
cursor: pointer;
}
If you see mistakes or want to suggest changes, please create an issue on the source repository.
For attribution, please cite this work as
Briggs (2021, Dec. 18). Jim's Docs: Dealing with Images in R. Retrieved from https://jimsdocs.jimbrig.com/posts/2021-12-18-1-dealing-with-images-in-r/
BibTeX citation
@misc{briggs2021dealing, author = {Briggs, Jimmy}, title = {Jim's Docs: Dealing with Images in R}, url = {https://jimsdocs.jimbrig.com/posts/2021-12-18-1-dealing-with-images-in-r/}, year = {2021} }