MyNixOS website logo
Description

Crops an Image to a Circle.

Images are cropped to a circle with a transparent background. The function takes a vector of images, either local or from a link, and circle crops the image. Paths to the cropped image are returned for plotting with 'ggplot2'. Also includes cropping to a hexagon, heart, parallelogram, and square.

cropcircles

Crop an image into a circle with a transparent background.

The purpose of this package is to provide a simple and straight forward way to circle crop an image, with a transparent background and plot it with ggimage, ggpath, or include in tables using e.g. gt, reactable, etc. There are a few ways to do this, but this package intends to make it as simplified as possible.

Release notes

Version 0.2.4 has changed the function naming convention to crop_*. circle_crop and hex_crop are still available and work the same way so won’t break existing code but will be deprecated at some stage.

Installation

From CRAN

install.packages("cropcircles")

Or Git

devtools::install_github("doehm/cropcircles")

Usage

The main function crop_circle takes a vector of image paths, either local or URL links, crops the image and returns the path. The path of the cropped images can be provided or if left blank it will save them to a temp location which is cleared when the session ends.

A border can be added by specifying the size (in pixels) and colour.

library(cropcircles)
library(magick)
## Linking to ImageMagick 6.9.12.93
## Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
## Disabled features: fontconfig, x11
img_path <- file.path(system.file(package = "cropcircles"), "images", "walter-jesse.png")

# saves to a temporary path
img_cropped <- crop_circle(img_path, border_size = 4)

# plot image with magic
# can be used with ggimage or ggpath
image_read(img_cropped)
# other geometries

image_read(crop_hex(img_path, border_size = 4))
image_read(crop_heart(img_path, border_size = 4))
image_read(crop_parallelogram(img_path, border_size = 4))

The function can take an image with any dimensions. It will circle crop the image from the center with a diameter of the smallest dimension.

Justify

With rectangular images the subject for focus may not be centered. The crop_* functions include a just argument which can take values left, right, top and bottom. It simply shifts the initial cropping window to the desired side.

library(magick)

# justification example
img_path <- file.path(system.file(package = "cropcircles"), "images", "walter-jesse.png")
orig <- image_read(img_path)

# center (default)
center <- image_read(crop_circle(img_path, border_size = 4))

# left
left <- image_read(crop_circle(img_path, border_size = 4, just = "left"))

# right
right <- image_read(crop_circle(img_path, border_size = 4, just = "right"))

image_montage(c(orig, center, left, right))
Metadata

Version

0.2.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows