Title: | Crops an Image to a Circle |
---|---|
Description: | 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. |
Authors: | Daniel Oehm [aut, cre] |
Maintainer: | Daniel Oehm <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.4 |
Built: | 2025-02-23 02:45:29 UTC |
Source: | https://github.com/doehm/cropcircles |
Add border helper
add_border(x, geom, border_size, border_colour, bg_fill, orig)
add_border(x, geom, border_size, border_colour, bg_fill, orig)
x |
magick image |
geom |
Geometric shape e.g. circle, hex, heart. |
border_size |
Border size in pixels. |
border_colour |
Border colour |
bg_fill |
Background fill |
orig |
List of original dimensions e.g. 'list(wd = 100, ht = 200)' |
Magick image
Reads in an image and crops to the specified geometry with a transparent background. If a new path is given it will save the cropped images to the new location. If no path is given it will save to a temporary location which will be cleared when the session is closed
crop_circle( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_square( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_hex( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_heart( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_parallelogram( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) circle_crop( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) hex_crop( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" )
crop_circle( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_square( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_hex( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_heart( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) crop_parallelogram( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) circle_crop( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" ) hex_crop( images, to = NULL, border_size = NULL, border_colour = "black", bg_fill = NULL, just = "center" )
images |
Vector of image paths, either local or urls. If urls the images will be downloaded first. |
to |
Path to new location |
border_size |
Border size in pixels. |
border_colour |
Border colour. |
bg_fill |
Background fill. Allows a different colour for the background and a different colour for the border. |
just |
Where to justify the image prior to cropping. Accepted values: 'left', 'right', 'top', 'bottom' |
Path to cropped images
The naming convention is now 'crop_*'. The old functions 'circle_crop' and 'hex_crop' still work but you are encouraged to use the new functions 'crop_circle' and 'crop_hex'.
library(cropcircles) library(magick) img_path <- file.path(system.file(package = "cropcircles"), "images", "walter-jesse.png") img_cropped <- crop_circle(img_path, border_size = 6) image_read(img_cropped) # other geometries image_read(crop_hex(img_path, border_size = 6)) image_read(crop_heart(img_path, border_size = 6)) image_read(crop_parallelogram(img_path, border_size = 6)) # justification example # center (default) image_read(crop_circle(img_path, border_size = 6)) # left image_read(crop_circle(img_path, border_size = 6, just = "left")) # right image_read(crop_circle(img_path, border_size = 6, just = "right"))
library(cropcircles) library(magick) img_path <- file.path(system.file(package = "cropcircles"), "images", "walter-jesse.png") img_cropped <- crop_circle(img_path, border_size = 6) image_read(img_cropped) # other geometries image_read(crop_hex(img_path, border_size = 6)) image_read(crop_heart(img_path, border_size = 6)) image_read(crop_parallelogram(img_path, border_size = 6)) # justification example # center (default) image_read(crop_circle(img_path, border_size = 6)) # left image_read(crop_circle(img_path, border_size = 6, just = "left")) # right image_read(crop_circle(img_path, border_size = 6, just = "right"))
Circle crop helper
cut_circle(x, just = "center")
cut_circle(x, just = "center")
x |
Magick images |
just |
Where to justify the image prior to cropping |
Magick image
heart crop helper
cut_heart(x, just = "center")
cut_heart(x, just = "center")
x |
Magick image |
just |
Where to justify the image prior to cropping |
Magick images
Hex crop helper
cut_hex(x, just = "center")
cut_hex(x, just = "center")
x |
Magick image |
just |
Where to justify the image prior to cropping |
Magick image
Parallelogram crop helper
cut_parallelogram(x, just = "center")
cut_parallelogram(x, just = "center")
x |
Magick image |
just |
Where to justify the image prior to cropping |
Magick image
Square crop helper
cut_square(x, just = "center")
cut_square(x, just = "center")
x |
Magick images |
just |
Where to justify the image prior to |
Magick image