feat(profile): crop avatar/logo before upload (round mask by default)#131
feat(profile): crop avatar/logo before upload (round mask by default)#131dantaspaulo wants to merge 1 commit into
Conversation
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.
|
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:
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 |
|
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: I will merge soon. |
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.
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 roundmask by default. Save produces a
canvas.toBlob→Filethat is uploadedalready cropped and resized (512×512 output, well under the 2 MB limit).
The integration lives in one place —
PhotoUpload.vue, used by both the profileavatar 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,RectangleStencilfor a square shape).PhotoUpload.vue— opens the crop before uploading.lang/{en,es,pt-BR}/common.php—photo_upload.crop_*strings.New dependency
This adds
vue-advanced-cropper(^2.8.9). It's a mature, Vue 3-compatiblecropper; the
package-lock.jsonchange is limited to that subtree(
classnames,debounce,easy-bem,vue-advanced-cropper). Happy to swap itfor another cropper if you'd prefer a different one.