code: def _crop_img_to(img, slices, copy=True):
      """Crops an image to a smaller size.
  
      Crop `img` to size indicated by slices and adjust affine accordingly.
  
      Parameters
      ----------
      img : Niimg-like object
          Image to be cropped.
          If slices has less entries than `img` has dimensions,
          the slices will be applied to the first `len(slices)` dimensions
          (See :ref:`extracting_data`).
  
      slices : list of slices
          Defines the range of the crop.
          E.g. [slice(20, 200), slice(40, 150), slice(0, 100)] defines a cube.
  
      copy : :obj:`bool`, default=True
          Specifies whether cropped data is to be copied or not.
  
      Returns
      -------
      Niimg-like object
          Cropped version of the input image.
  
      offset : :obj:`list`, optional
          List of tuples representing the number of voxels removed
          (before, after) the cropped volumes, i.e.:
          *[(x1_pre, x1_post), (x2_pre, x2_post), ..., (xN_pre, xN_post)]*
  
      """
      img = check_niimg(img)
  
      data = get_data(img)
      affine = img.affine
  
      cropped_data = data[tuple(slices)]
      if copy:
          cropped_data = cropped_data.copy()
  
      linear_part = affine[:3, :3]
      old_origin = affine[:3, 3]
      new_origin_voxel = np.array([s.start for s in slices])
      new_origin = old_origin + linear_part.dot(new_origin_voxel)
  
      new_affine = np.eye(4)
      new_affine[:3, :3] = linear_part
      new_affine[:3, 3] = new_origin
  
      return new_img_like(img, cropped_data, new_affine)
  
imports: import collections.abc
  import copy
  import itertools
  import warnings
  import nibabel
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy.ndimage import gaussian_filter1d, generate_binary_structure, label
  from scipy.stats import scoreatpercentile
  from ..None import signal
  from .._utils import _repr_niimgs, as_ndarray, check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.exceptions import DimensionError
  from .._utils.helpers import rename_parameters, stringify_path
  from .._utils.niimg import _get_data, safe_get_data
  from .._utils.niimg_conversions import _index_img, check_same_fov, iter_check_niimg
  from .._utils.param_validation import check_threshold
  from .._utils.path_finding import resolve_globbing
label_desc: Use image node_id 6 for calling a global function with example usage: _crop_img_to(img, slices, copy) and returns: new_img_like