Skip to content
animorio
IT
Back to the library

Image cropper

Images, HoverGSAP, CSS onlyMediumCompressed weight: Demo 12 KBGSAP 28 KBFreeDownload the zip

The crop tool of a made-up photo editor, Arca Photo, dark with a single amber accent: the frame with four corner handles and four side handles over a real photo of a coast at sunset with a crooked horizon, the grid of thirds that shows while you drag, the formats Free, 1:1, 4:5 and 16:9 that spring the frame around the same centre, and the straighten dial: a ruler from -45° to +45° sliding under a fixed index, turning the photo and zooming it just enough that no empty corner shows, with the degrees rolling. Reset and Done. Minimal style.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Image cropper" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Crop, Arca Photo</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- the crop tool of a made-up photo editor, Arca Photo: the photo with the crop frame on top (four corner handles,
       four side handles), the dimmed photo outside the frame, the grid of thirds while you drag, the formats at the
       bottom (Free, 1:1, 4:5, 16:9) and the straighten dial, a ruler from -45 to +45 degrees under a fixed index -->
  <main class="pagina">
    <section class="editor" data-editor aria-label="Crop and straighten">
      <header class="barra">
        <button class="reset" type="button" data-reset disabled>
          <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3.2 6.4A5 5 0 1 1 3 9.6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/><path d="M2.6 2.9v3.6h3.6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
          <span>Reset</span>
        </button>
        <div class="titolo">
          <span class="titolo__nome">Crop</span>
          <span class="titolo__dim" data-dim>6000 × 4000</span>
        </div>
        <button class="fatto" type="button" data-fatto>
          <span class="fatto__luce" aria-hidden="true"></span>
          <span class="fatto__finestra">
            <span class="fatto__riga" data-fatto-riga>
              <span class="fatto__voce">Done</span>
              <span class="fatto__voce">
                <svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true"><path data-spunta d="M3.5 8.4l2.9 2.8 6-6.4" pathLength="1" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
                Saved
              </span>
            </span>
          </span>
        </button>
      </header>

      <div class="tavolo" data-tavolo>
        <div class="foto" data-foto>
          <img src="costa.webp" alt="The sea stacks of a rocky coast at sunset, the horizon a little crooked" width="880" height="587" draggable="false">
        </div>
        <div class="cornice" data-cornice>
          <span class="griglia griglia--fine" data-fine aria-hidden="true"></span>
          <span class="griglia griglia--terzi" data-terzi aria-hidden="true">
            <i class="v" style="left: 33.333%"></i><i class="v" style="left: 66.667%"></i>
            <i class="o" style="top: 33.333%"></i><i class="o" style="top: 66.667%"></i>
          </span>
          <span class="maniglia maniglia--angolo" data-maniglia="nw" style="left: 0; top: 0"><span class="segno"><svg viewBox="0 0 22 22"><path d="M2 20V2h18"/></svg></span></span>
          <span class="maniglia maniglia--angolo" data-maniglia="ne" style="left: 100%; top: 0"><span class="segno"><svg viewBox="0 0 22 22" style="transform: rotate(90deg)"><path d="M2 20V2h18"/></svg></span></span>
          <span class="maniglia maniglia--angolo" data-maniglia="se" style="left: 100%; top: 100%"><span class="segno"><svg viewBox="0 0 22 22" style="transform: rotate(180deg)"><path d="M2 20V2h18"/></svg></span></span>
          <span class="maniglia maniglia--angolo" data-maniglia="sw" style="left: 0; top: 100%"><span class="segno"><svg viewBox="0 0 22 22" style="transform: rotate(270deg)"><path d="M2 20V2h18"/></svg></span></span>
          <span class="maniglia maniglia--lato maniglia--o" data-maniglia="n" style="left: 50%; top: 0"><span class="segno"></span></span>
          <span class="maniglia maniglia--lato maniglia--v" data-maniglia="e" style="left: 100%; top: 50%"><span class="segno"></span></span>
          <span class="maniglia maniglia--lato maniglia--o" data-maniglia="s" style="left: 50%; top: 100%"><span class="segno"></span></span>
          <span class="maniglia maniglia--lato maniglia--v" data-maniglia="w" style="left: 0; top: 50%"><span class="segno"></span></span>
        </div>
      </div>

      <div class="ghiera">
        <div class="ghiera__valore" data-valore aria-hidden="true">
          <span class="meno" data-meno>&minus;</span>
          <span class="cifra cifra--decine" data-cifra="2"><span class="nastro-cifre"></span></span>
          <span class="cifra" data-cifra="1"><span class="nastro-cifre"></span></span>
          <span class="punto">.</span>
          <span class="cifra" data-cifra="0"><span class="nastro-cifre"></span></span>
          <span class="grado">&deg;</span>
        </div>
        <div class="righello" data-righello role="slider" tabindex="0" aria-label="Straighten" aria-valuemin="-45" aria-valuemax="45" aria-valuenow="0" aria-valuetext="0 degrees">
          <svg class="righello__nastro" data-nastro aria-hidden="true"></svg>
          <span class="righello__indice" data-indice aria-hidden="true"></span>
        </div>
      </div>

      <div class="formati" role="radiogroup" aria-label="Format" data-formati>
        <span class="formati__pillola" data-pillola aria-hidden="true"></span>
        <button type="button" role="radio" aria-checked="true" data-formato="free"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3"/></svg><span>Free</span></button>
        <button type="button" role="radio" aria-checked="false" data-formato="1:1"><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="3" y="3" width="10" height="10" rx="1.5"/></svg><span>1:1</span></button>
        <button type="button" role="radio" aria-checked="false" data-formato="4:5"><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="3.5" y="2" width="9" height="12" rx="1.5"/></svg><span>4:5</span></button>
        <button type="button" role="radio" aria-checked="false" data-formato="16:9"><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="1.5" y="4" width="13" height="8" rx="1.5"/></svg><span>16:9</span></button>
      </div>

      <svg class="dito" data-dito viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M5 3.2l13.6 8.1-6 1.2-3 5.6z" fill="#fff" stroke="#111" stroke-width="1.3" stroke-linejoin="round"/></svg>
    </section>
  </main>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

29 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Image cropper” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On an almost black ground, with a warm glow coming from the photo, the dark window of Arca Photo, a made-up photo editor, open on the Crop tool. At the top Reset (off until something changes), the title with the crop’s size in pixels changing as you work (6000 × 4000 at first) and the amber Done button. In the middle a real photo of a coast at sunset, with sea stacks in the water, taken with the horizon three and a half degrees off. Over the photo the crop frame: a thin white line, four thicker L corners and four marks halfway along the sides. Outside the frame the photo is dark; while you drag a handle it lightens a little to show what you are leaving out, the handle under the finger grows and the grid of thirds shows up, fading slowly when you let go. Below, the straighten dial: a ruler with a tick for every degree from -45 to +45, longer every five degrees, numbers every fifteen and zero in amber, sliding under a fixed index; the ticks near the index light up. Dragging it turns the photo around its centre and zooms it just enough that no empty corner is ever left inside the frame, a fine grid shows up to line up the horizon and the value in degrees rolls like an odometer; let go, the ruler runs on a little and lands on a tenth of a degree, and near zero it snaps with a small knock of the index. At the bottom the formats Free, 1:1, 4:5 and 16:9: a pill slides under the chosen one and the frame springs to the new shape, the biggest that fits around the same centre. Done darkens the outside, folds the handles, runs a light over the button and rolls to Saved with a tick drawing itself; Reset puts everything back with its arrow turning once. Left alone, a drawn pointer drags a corner, picks 4:5, straightens by -3.5°, presses Done, then Reset, and starts again.

How it works

The frame in shares of the photo

The crop is kept in shares of the photo (x, y, width and height between 0 and 1), not in pixels: on resize only the photo’s box is measured again and the frame stays where it was. The dark outside is a huge box-shadow of the frame, cut by the table with overflow: hidden; its opacity is a CSS variable GSAP animates. A corner with a format chosen keeps the shape: the wider move wins, the opposite corner stays put and if it leaves the photo everything shrinks together.

The zoom that covers the corners

Every frame the four corners of the crop are taken relative to the photo’s centre, turned by the opposite angle, and measured against the photo: the zoom is the largest of those ratios, never under 1. So the turned photo always covers the frame, even while the frame springs to a new shape, and the pixel size in the title is divided by the same zoom.

The ruler and the odometer

The ruler is an SVG with a line per degree, moved with translateX by STEP pixels a degree; each tick’s opacity depends on its distance from the index. The value is three columns of digits: the tenths roll continuously with the value, the others move only in the last tenth before the carry, like an odometer. On release the finger’s speed gives a little momentum and the landing is rounded to a tenth.

Values to change

NameFileDefaultWhat it changes
SPRINGscript.js0.75Seconds the frame takes to spring to a new format.
STEPscript.js7Pixels between two degrees on the ruler.
SHADEscript.js0.66How dark the photo is outside the frame, at rest.
SHADE_WORKscript.js0.42How dark it is while you drag or straighten.
GRID_FADEscript.js0.6Seconds the grid takes to fade when you let go.
MAGNETscript.js0.4Degrees around zero where the dial snaps straight.
MIN_SIZEscript.js0.2The smallest frame, as a share of the photo’s side.
AUTOscript.js1Seconds before the tour starts by itself.
IDLEscript.js6Seconds without a touch before the tour comes back.

Try them in the Playground

When to use it

For a photo editor, an image upload in an app or a dashboard (covers, product photos, article images), or a photography site: wherever someone uploading a photo needs to crop it to a set format and straighten it before saving.

On phones

The same animations: the window takes the whole box, the heights of the bar, dial and formats are also in vh, the photo fits the space left; under 420 pixels the pixel size and the format icons hide. With a finger the handles and the ruler drag as with the mouse.

With reduced motion

No springs, no animated turning and no drawn pointer: the frame, the angle and the formats change at once, the grids and the dark outside fade.

Pitfalls

  • The zoom is worked out every frame from the frame as it is at that moment, not only at the end: while the formats spring, the frame passes through wider shapes and would show empty corners for an instant.
  • The drag is divided by how much the viewer has shrunk the demo (width from getBoundingClientRect over clientWidth), or in the page the frame runs ahead of the finger.
  • The corner L shapes are offset with the SVG’s left and top, not with a transform on the handle: GSAP animates the mark’s scale and its transform would wipe out the class’s offset.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 12 KB; the libraries: GSAP 28 KB.

Testing

Tested on 21 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations