% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/render_crop.R
\name{render_crop}
\alias{render_crop}
\title{Crop Image}
\usage{
render_crop(
  image = NULL,
  width_limits = NULL,
  height_limits = NULL,
  center = NULL,
  filename = NULL,
  preview = FALSE
)
}
\arguments{
\item{image}{Default \code{NULL}. 3-layer RGB/4-layer RGBA array, \code{rayimg} class, or filename of an image.}

\item{width_limits}{Default \code{NULL}. Length-2 numeric \verb{(xmin, xmax)} along the width (x/columns).
Values in 0..1 are treated as fractions of image width; otherwise they are pixel indices.
Mutually exclusive with \code{center}. If provided alone, \code{height_limits} defaults to full height.}

\item{height_limits}{Default \code{NULL}. Length-2 numeric \verb{(ymin, ymax)} along the height (y/rows).
Values in 0..1 are treated as fractions of image height; otherwise they are pixel indices.
Mutually exclusive with \code{center}. If provided alone, \code{width_limits} defaults to full width.}

\item{center}{Default \code{NULL}. Length-2 numeric \verb{(height, width)} for a center-crop.
Values in (0,1] are treated as fractions of \verb{(image height, image width)}; otherwise pixels.
Mutually exclusive with \code{width_limits}/\code{height_limits}.}

\item{filename}{Default \code{NULL}. The filename of the image to be saved. If this is not given, the image will be plotted instead.}

\item{preview}{Default \code{FALSE}. Whether to plot the cropped image, or just to return the values.}
}
\value{
A \code{rayimg} array with the cropped region.
}
\description{
Crops an image (or matrix) either by specifying axis-aligned limits
(\code{width_limits}/\code{height_limits}) or by specifying a centered box size via \code{center}.
}
\examples{
\dontshow{if (interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")) withAutoprint(\{ # examplesIf}
# Left half of the image
render_crop(dragon,
           width_limits = c(0, 0.50),
           height_limits = c(0, 1)) |>
 plot_image()
# Right half of the image
render_crop(dragon,
           width_limits = c(0.50, 1),
           height_limits = c(0, 1)) |>
 plot_image()
# Top middle of the image (25\%–50\% height, 25\%–75\% width)
render_crop(dragon,
           height_limits = c(0.25, 0.50),
           width_limits  = c(0.25, 0.75)) |>
 plot_image()
# Top middle, explicit pixel coords (for a 200x200 image)
render_crop(dragon,
           height_limits = c(50, 100),
           width_limits  = c(50, 150)) |>
 plot_image()
# Center-crop: 50\% height and width of the image
render_crop(dragon, center = c(0.5, 0.5)) |>
 plot_image()
# Center-crop: fixed 50x100 pixels
render_crop(dragon, center = c(50, 100)) |>
 plot_image()
\dontshow{\}) # examplesIf}
}
