Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): properly project profile picture #16095

Merged
merged 4 commits into from
Feb 14, 2025

Conversation

immangat
Copy link
Contributor

Description

This PR fixes an issue where users were unable to set a profile picture due to incorrect transparency detection. The issue originates from the hasTransparentPixels function in profile-image-cropper.svelte.

Root Cause

The issue occurs because the blob generated in the handleSetProfilePicture function does not accurately represent the portion of the image selected by the user. Users can zoom and drag the image in the photo-viewer component, but the generated blob includes additional image areas and empty canvas space, leading to incorrect transparency detection.

When the blob is projected onto a canvas for transparency checking, the canvas contains:

  1. The user-selected portion of the image.
  2. Additional unwanted portions of the image.
  3. Empty space around the image, leading to incorrect transparency detection.

Since the hasTransparentPixels function evaluates the entire canvas, the presence of empty space causes false positives, preventing users from setting their profile pictures.

Solution

  1. When the blob is generated it uses the imgElement height and width to only get portion of the image that the user has selected.

This fix ensures both transparency detection and the final profile picture selection work as expected.

Fixes #15812.

How Has This Been Tested?

This PR has been tested manually with different image types:

  • ✅ Transparent images
  • ✅ Semi-transparent images
  • ✅ Standard images (JPG, PNG, WEBP)

Before the Fix:

  1. User-selected image:
    Screenshot 2025-02-13 at 5 40 22 PM

  2. Image projected onto canvas (incorrect):
    Note: Contains empty space and additional image areas beyond the user’s selection.
    Screenshot 2025-02-13 at 5 40 33 PM

After Transparency Fix:

  1. User-selected image:
    Screenshot 2025-02-13 at 5 41 02 PM

  2. Image projected onto canvas (corrected):
    Note: Now accurately reflects only the selected portion of the image.
    Screenshot 2025-02-13 at 5 41 17 PM

After Fix:

Note: The selected profile pic now correctly matches the user’s selection.
Screenshot 2025-02-13 at 6 48 14 PM

Further Considerations

⚠️⚠️⚠️⚠️

Note: The root issue may actually stem from how the blob is initially generated, as it does not perfectly preserve the user’s selected image. A more comprehensive fix could involve refactoring the photo-viewer component to ensure the blob represents only the exact area chosen by the user. However, this PR provides a targeted fix by adjusting the height and width of the generated blob to correctly reflect the selected image.

Checklist:

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation, if applicable.
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have followed naming conventions and patterns in the surrounding code.

…transparency check

Fixed an issue where users could not set a profile picture due to incorrect transparency detection.
After addressing transparency detection by passing explicit dimensions, another issue arose where the
generated blob did not represent the correct cropped image area. To fix this, a new cropped blob was generated using the canvas that was used to check for transparent pixels.

- Pass image width and height explicitly to `hasTransparentPixels` for accurate processing.
- Return both transparency status and the correctly cropped image blob.
- Ensure the final uploaded image is taken from `croppedImageBlob` to reflect user adjustments.
…transparency check

Fixed an issue where users could not set a profile picture due to incorrect transparency detection.
To fix this, a new cropped blob was generated using the height and width of the imgElement.

Note: this is a simpler fix than the one in the previous commit.
@immangat immangat marked this pull request as ready for review February 14, 2025 03:13
@bo0tzz bo0tzz changed the title Fix/web profile pic set fix(web): properly project profile picture Feb 14, 2025
@alextran1502 alextran1502 enabled auto-merge (squash) February 14, 2025 15:44
@alextran1502 alextran1502 merged commit b1f05fc into immich-app:main Feb 14, 2025
33 of 35 checks passed
@immangat immangat deleted the fix/web-profile-pic-set branch February 15, 2025 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Can't set profile picture
4 participants