Getting startedComponentsDesign tokensThemingTheme synthesizerFrameworksAccessibilityUtilitiesServer renderingBrowser supportContributingChangelogApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip
ARC UIARC Radiant Components
v4.9DocsComponentsTokensSynthesizer
Getting startedFrameworksServer renderingDesign tokensThemingTheme synthesizerTypographyUtilitiesAll componentsAccessibilityBrowser supportChangelogContributingStatsApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip

Image Cropper

Crop-before-upload control: drag and resize a crop rectangle, lock its aspect ratio, zoom, and export the crop at the image's natural resolution.

ComponentsImage Cropper
inputinteractivebeta
<arc-image-cropper>

Overview

Image Cropper shows an image letterboxed in a fixed-height stage with a crop rectangle over it. People drag the rectangle to move it and pull its eight handles (four corners, four edges) to resize it. Everything outside the rectangle is darkened, and rule-of-thirds lines sit inside it. A zoom slider under the stage scales the image around its center from 1x to 4x while the rectangle stays put. `aspect` (width/height, such as `1` for a square avatar or `16/9`) locks the rectangle to that ratio through every drag, resize, zoom and key press. Leave it at `0` for a free-form crop. The rectangle always stays inside the image and never gets smaller than 32px. Three methods read the result. `getCrop()` returns `{ x, y, width, height }` in the image's natural pixels, with letterboxing and zoom already accounted for. `getCroppedBlob(type, quality)` and `getCroppedDataUrl(type, quality)` draw the crop to an offscreen canvas at natural resolution. Export only works when `src` is same-origin or served with CORS headers. A cross-origin image taints the canvas, and the methods throw an error that says so. `arc-crop-change` fires with the same natural-pixel coordinates, at most once per animation frame during a drag.

Guidelines

Do

  • Set `aspect="1"` for avatars so the exported crop is always square
  • Use an object URL (`URL.createObjectURL(file)`) as `src` when cropping a file just picked in `arc-file-upload`
  • Listen for `arc-crop-change` to show a live preview or save the crop coordinates
  • Call `getCroppedBlob()` at upload time to send the cropped region at natural resolution
  • Serve remote images from the same origin or with CORS headers so export works

Don't

  • Don't read crop coordinates from the rectangle on screen. `getCrop()` converts them to natural image pixels
  • Don't shrink `height` far below its 320px default. The rectangle and handles need room
  • Don't use it to frame an image for display. Use CSS `object-fit` or an aspect-ratio container

Features

  • Handles have touch-sized hit areas
  • Keyboard: focus the rectangle, then arrows move it 2px and Shift+arrows resize it from the bottom-right corner
  • Position and size are announced in a polite live region when a key is released
  • A skeleton shimmer shows while the image loads, and an inline error if it fails

Preview

Usage

This component needs JavaScript. Use the Web Component or a framework wrapper.

<arc-image-cropper
  src="/uploads/avatar-original.jpg"
  aspect="1"
  height="320"
></arc-image-cropper>

<script>
  const cropper = document.querySelector('arc-image-cropper');

  cropper.addEventListener('arc-crop-change', (e) => {
    console.log('Crop (natural px):', e.detail);
  });

  // At upload time — natural-resolution export:
  async function upload() {
    const blob = await cropper.getCroppedBlob('image/jpeg', 0.9);
    const body = new FormData();
    body.append('avatar', blob, 'avatar.jpg');
    await fetch('/api/avatar', { method: 'POST', body });
  }
</script>

API

srcstring''
Image URL, object URL, or data URL to crop. Must be same-origin or CORS-enabled for canvas export.
heightnumber320
Fixed stage height in pixels. The image is letterboxed to fit.
aspectnumber0
Crop aspect ratio as width/height (e.g. 1, 16/9). 0 allows free-form cropping.
zoomnumber1
Image zoom factor, clamped to 1-4 on the property as well as on the slider. Scales the image around its center; also settable via the built-in slider.

Methods

getCrop(){ x: number, y: number, width: number, height: number } | null
Current crop in natural image pixels, or null before the image has loaded.
getCroppedBlob(type?, quality?)type?: string, quality?: numberPromise<Blob>
Export the crop as a Blob at natural resolution.
getCroppedDataUrl(type?, quality?)type?: string, quality?: numberPromise<string>
Export the crop as a data URL at natural resolution.

Events

arc-crop-change
Fired when the crop changes (drag, resize, keyboard, zoom, stage resize). event.detail is { x, y, width, height } in natural image pixels, debounced to animation frames.

See also