Skip to content

feat(profile): crop avatar/logo before upload (round mask by default)#131

Closed
dantaspaulo wants to merge 1 commit into
trypostit:mainfrom
dantaspaulo:feat/avatar-logo-crop
Closed

feat(profile): crop avatar/logo before upload (round mask by default)#131
dantaspaulo wants to merge 1 commit into
trypostit:mainfrom
dantaspaulo:feat/avatar-logo-crop

Conversation

@dantaspaulo

Copy link
Copy Markdown
Contributor

Problem

Avatar/logo upload is raw: any aspect ratio goes straight to the server, so the
circular avatar ends up off-center. Since the avatar/logo also renders as a
circle on generated cards, letting the user frame it improves the result a lot.

Change

Selecting a file now opens an ImageCropperDialog (zoom + drag) with a round
mask by default
. Save produces a canvas.toBlobFile that is uploaded
already cropped and resized (512×512 output, well under the 2 MB limit).

The integration lives in one place — PhotoUpload.vue, used by both the profile
avatar and the workspace logo. The cropper mounts only after the dialog has its
final layout, otherwise the circular stencil degrades into a square inside the
modal.

  • ImageCropperDialog.vue (new) — the crop modal (CircleStencil, RectangleStencil for a square shape).
  • PhotoUpload.vue — opens the crop before uploading.
  • lang/{en,es,pt-BR}/common.phpphoto_upload.crop_* strings.

New dependency

This adds vue-advanced-cropper (^2.8.9). It's a mature, Vue 3-compatible
cropper; the package-lock.json change is limited to that subtree
(classnames, debounce, easy-bem, vue-advanced-cropper). Happy to swap it
for another cropper if you'd prefer a different one.

Avatar/logo upload was raw: any aspect ratio went straight to the server, so
the circular avatar ended up off-center. Since the avatar/logo also renders as a
circle on generated cards, letting the user frame it improves the result a lot.

Selecting a file now opens an ImageCropperDialog (zoom + drag) with a round mask
by default; Save produces a canvas.toBlob -> File that gets uploaded already
cropped and resized (512x512 output, well under the 2 MB limit). The integration
lives in one place, PhotoUpload.vue, used by both the profile avatar and the
workspace logo. The cropper mounts only after the dialog has its final layout,
otherwise the circular stencil degrades into a square inside the modal.

Adds the vue-advanced-cropper dependency.

- ImageCropperDialog.vue (new): the crop modal (vue-advanced-cropper, CircleStencil).
- PhotoUpload.vue: opens the crop before uploading.
- lang/{en,es,pt-BR}/common.php: photo_upload.crop_* strings.
@paulocastellano

Copy link
Copy Markdown
Contributor

Thanks a lot for this, @dantaspaulo — the UX idea is spot on. Cropping the avatar/logo before upload, with the mask matching how it actually renders, genuinely improves the result, and we want it in the product.

We're going to close this one in favor of a from-scratch implementation, for two reasons:

  1. The dependency. vue-advanced-cropper is effectively unmaintained — the last release (2.8.9) was June 2024, ~2 years ago. We'd rather not take on an abandoned package for something this load-bearing.

  2. The crop shape. Avatars and workspace logos don't render the same way (one's a circle, the other a rounded square), so the crop mask should follow the display shape instead of always being round.

Since what we need is narrow — fixed 1:1, a circle/square mask, fixed-size output — we're rebuilding it dependency-free with a small canvas-based cropper, which also lets us cover it with tests.

None of this takes away from the contribution: the idea and the integration points (the PhotoUpload flow, the i18n strings) were a great starting point and directly shaped the replacement. Really appreciate you taking the time — please keep them coming. 🙏

@dantaspaulo

Copy link
Copy Markdown
Contributor Author

That's great, @paulocastellano. I've taken your suggestion on board; I'm going to remove the current version from my end and implement it the way you described.

@paulocastellano

Copy link
Copy Markdown
Contributor

That's great, @paulocastellano. I've taken your suggestion on board; I'm going to remove the current version from my end and implement it the way you described.

I already implemented it:

#174

I will merge soon.

pull Bot pushed a commit to chewtoys/trypost that referenced this pull request Jul 4, 2026
Selecting an avatar or workspace logo now opens a crop dialog (drag + zoom)
before uploading, so the image is framed the way it renders. The crop is
performed client-side and the resized 512x512 result is what gets uploaded.

This reworks the idea from trypostit#131 without its cropper dependency: vue-advanced-cropper
was last released ~2 years ago and we did not want an unmaintained package for
something this load-bearing. What we need is narrow (fixed 1:1, a circle/square
mask, fixed-size output), so a small canvas-based cropper covers it:

- imageCrop.ts: pure transform math (cover-fit, clamp, zoom, viewport->source).
- ImageCropperDialog.vue: CSS-transform preview, pointer drag, wheel/button zoom,
  a ResizeObserver to measure the modal (no requestAnimationFrame timing hacks),
  and a canvas toBlob only on save.
- PhotoUpload.vue: opens the cropper on file select; the mask shape follows the
  display shape (round avatar / square logo) instead of always being round.
- crop_* strings added to all 15 locales.

Also installs Pest browser testing (pest-plugin-browser + Playwright) and adds a
browser test for the crop flow. TestCase only calls withoutVite() for non-browser
tests, since browser tests need the real Vite assets to boot the SPA. The Pest
browser server does not parse multipart uploads, so the test asserts the crop
dispatches the correct upload request; endpoint persistence stays covered by
ProfileUpdateTest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants