Skip to content
animorio
IT
Back to the library

Profile photo crop

Physics, HoverGSAP, CanvasMediumCompressed weight: Demo 8.1 KBGSAP 28 KBFreeDownload the zip

An app’s profile photo editor, small and precise in the style of one-gesture micro-interactions: a real portrait drags under the round crop, past the edge a rubber band that grows stiffer holds it and on release a spring brings it back inside, flung it glides and stops with friction. Zoom has its own slider, the rule-of-thirds grid shows only while you hold the photo, and Save shrinks the circle into the avatar at the top.

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>
<!--
  "Profile photo crop" 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>The profile photo crop you drag into place</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>
  <main class="stage" data-stage>
    <!-- the photo editor of a profile: drag the picture under the round frame, zoom with the slider,
         the edges hold it on a rubber band and it settles back with a spring; Save shrinks it into the avatar -->
    <section class="card" data-card aria-label="Edit profile photo">
      <header class="card__head">
        <button class="txt" type="button" data-reset>Reset</button>
        <div class="head__mid">
          <div class="mini" data-mini aria-hidden="true"><canvas data-mini-canvas></canvas></div>
          <p class="head__title">
            <span class="head__state" data-title-edit>Profile photo</span>
            <span class="head__state head__state--done" data-title-done>Photo updated</span>
          </p>
        </div>
        <button class="save" type="button" data-save>
          <span class="save__label" data-save-label>Save</span>
          <svg class="save__check" data-save-check viewBox="0 0 24 24" aria-hidden="true"><path d="M6 12.5 10.2 16.5 18 8" pathLength="1"></path></svg>
        </button>
      </header>

      <div class="crop" data-crop>
        <canvas class="crop__photo" data-photo aria-label="Photo, drag to move"></canvas>
        <svg class="crop__mask" data-mask aria-hidden="true">
          <defs>
            <mask id="buco">
              <rect width="100%" height="100%" fill="#fff"></rect>
              <circle data-hole fill="#000"></circle>
            </mask>
          </defs>
          <rect width="100%" height="100%" fill="rgba(12,12,14,0.58)" mask="url(#buco)"></rect>
          <g class="crop__grid" data-grid>
            <line data-g="v1"></line><line data-g="v2"></line><line data-g="h1"></line><line data-g="h2"></line>
          </g>
          <circle class="crop__ring" data-ring></circle>
        </svg>
        <p class="crop__hint" data-hint>Drag to reposition</p>
      </div>

      <div class="zoom">
        <svg class="zoom__icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6"></circle><path d="M15 15l4.5 4.5M8 10.5h5"></path></svg>
        <div class="zoom__track" data-track role="slider" tabindex="0" aria-label="Zoom" aria-valuemin="100" aria-valuemax="300" aria-valuenow="100">
          <div class="zoom__fill" data-zfill></div>
          <div class="zoom__knob" data-knob></div>
        </div>
        <svg class="zoom__icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6"></circle><path d="M15 15l4.5 4.5M8 10.5h5M10.5 8v5"></path></svg>
        <span class="zoom__val" data-zval>1.0x</span>
      </div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </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.

20 values to change

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 “Profile photo crop” 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 a very light grey sits a white card: at the top Reset on the left, the title Profile photo in the middle and the black Save button on the right; in the middle the photo, a real portrait of a blonde young woman with dark lipstick in front of a chain-link fence at dusk, covered by a dark veil outside a thin white circle; below, the zoom slider between two magnifiers and the value, 1.0x. You grab the photo and drag it: it follows your hand, the circle gets a little thicker and the rule-of-thirds grid appears. Pull it past the point where the circle would be left uncovered and the photo keeps coming but less and less, as if held by a rubber band; let go and a short spring brings it back inside. Fling it and it glides and slows with friction, and if it reaches the edge the spring stops it. The zoom slider enlarges around the centre (so do the wheel and the arrow keys), and after the first gesture Reset lights up. Save squashes, turns green with a check drawing itself, the circle flashes and its photo, shrunk, appears as an avatar next to the title, which rolls to Photo updated. The fake pointer does it all by itself: pulls past the edge, flings, zooms, puts the face in the middle of the circle and saves; then it starts again.

How it works

The crop limit

The photo is a real portrait cut square and drawn into the canvas, as big as the frame’s long side times the zoom. The circle stays covered as long as the offset is within (photo side minus circle diameter) divided by two, on each axis: that is the limit, and it grows with zoom.

The rubber band past the edge

While dragging, the part past the limit goes through a hyperbolic tangent: L times tanh(overshoot divided by L). Near the edge the photo follows almost one to one, then less and less, and never goes beyond L, a fraction of the circle set by RUBBER.

Inertia, friction and spring

On release the speed is taken from the last 90 milliseconds of the gesture. On GSAP’s ticker, inside the limit the speed decays with friction, outside it a damped spring (stiffness 260 times SPRING, damping just under critical) brings it back to the edge without long bounces.

The circle that becomes the avatar

The veil is a rectangle with an SVG mask that has a round hole; the circle and the grid live in the same SVG. Save copies the circle’s square from the canvas into a 22 pixel canvas, which pops in next to the title as the title rolls over.

Values to change

NameFileDefaultWhat it changes
MAX_ZOOMscript.js3How far the photo can be zoomed (1 = as it fits).
RUBBERscript.js0.55How far it lets you pull past the edge before the rubber band stops it.
SPRINGscript.js1How stiff the spring that brings it back inside the circle is.
FRICTIONscript.js0.9How far it glides after a fling: higher goes further.
RINGscript.js1.5The thickness of the crop circle, in pixels.
SHADEscript.js0.58How dark the outside of the circle is.
ACCENTscript.js#12a150The colour of the confirmation.
HOLDscript.js1.8The seconds the confirmation stays before starting again.

Try them in the Playground

When to use it

For the profile photo of an app, an account or a community, and anywhere you choose how to frame an image before uploading it: a podcast cover, a team logo, a product photo.

On phones

The card takes almost the whole width of the box and the photo frame is sized on the height too; with a finger the photo drags and flings as with the mouse, without scrolling the page.

With reduced motion

No rubber band, spring or glide: the photo follows the finger and always stays within the limit; the autopilot only shows the states and the confirmation fades in.

Pitfalls

  • The dark veil with a round hole is an SVG mask (white rectangle, black circle): a huge box-shadow on a circle looks simpler but does not line up to the pixel with the canvas when the box changes height.
  • When zooming, the offset must be multiplied by the ratio of new to old zoom, or the photo slides away from the framed point.
  • The physics runs on GSAP’s ticker, not on its own requestAnimationFrame: that way the preview clock drives it and the video comes out the same every time.
  • touch-action: none on the frame and on the slider, or on a phone dragging scrolls the page.
  • The photo is drawn into the canvas only once it has loaded: the loop starts after image.decode(), or the first drag moves an empty frame and the saved avatar comes out black.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 5 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