f = xfun:::all_files("[.](png|jpe?g)$", R.home("doc"))
file.copy(f, tempdir())
f = file.path(tempdir(), basename(f))
magick::image_info(magick::image_read(f)) # some widths are larger than 300
xfun::shrink_images(300, files = f)
magick::image_info(magick::image_read(f)) # all widths <= 300 now
file.remove(f)
Run the code above in your browser using DataLab