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

feat(NcBlurHash): Add a blur hash component #6396

Merged
merged 1 commit into from
Feb 28, 2025
Merged

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Jan 18, 2025

☑️ Resolves

This allows to include image previews / placeholders in apps.

Currently something similar is used for the files and for the photos app. So this can be used to de-duplicate code.

🖼️ Screenshots

🏚️ Image 🏡 BlurHash
Screenshot 2025-01-18 at 22-34-54 Nextcloud Vue Style Guide Screenshot 2025-01-18 at 22-35-04 Nextcloud Vue Style Guide

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable
  • 3️⃣ Backport to next requested with a Vue 3 upgrade

@susnux susnux added enhancement New feature or request 3. to review Waiting for reviews component Component discussion and/or suggestion labels Jan 18, 2025
@susnux susnux added this to the 8.23.0 milestone Jan 18, 2025
@susnux
Copy link
Contributor Author

susnux commented Jan 18, 2025

/backport to next

Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, can't tell a difference from current in-Talk solution:
image

@susnux susnux requested a review from ShGKme January 20, 2025 13:35
Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it should be a part of this component, but when used, this element must have exactly the same aspect ratio as the original image. And when the image is loaded, it should be replaced with the image.

Having all that it seems to me, a developer still has to implement manually even more, than this component does.

Could you link places where you use this component? To see if we can reuse more.

Talk: https://github.com/nextcloud/spreed/blob/d4bf99ab8f7d522d4933d16cd7eb8ec388eefeeb/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue#L39

return
}

const { height, width } = canvas.value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, 32x32 is enought for the blurhash. Then we can just use CSS for scaling it.
cc @Antreesy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I remember it, with different dimensions a blurred thumbnail was quite distorted and different from original image, than 32*32 canvas. At least that's what upstream lib is using in demo:
https://blurha.sh/
nextcloud/spreed@0fe0f01

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a linear interpolation of a gradient, so scaling could lead to pixeled output if the image is rather big (nor sure how smart browsers scale images).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the canvas size is the way to go, as we do not always render square images. As long as the original image ratio is preserved, then it is fine.

@susnux
Copy link
Contributor Author

susnux commented Jan 20, 2025

Having all that it seems to me, a developer still has to implement manually even more, than this component does.

Not sure as this can also lead to overengineering.
I have updated the docs with a proper example on how to use it.

The user could have different use cases (maybe its not a placeholder but just the preview?), so what I could imagine:
Add source or href prop that is used to preload an image and if ready replace the canvas with an img tag with that href

@susnux susnux force-pushed the feat/nc-blur-hash branch from e1c4c5b to e9ff77f Compare January 20, 2025 21:29
@susnux
Copy link
Contributor Author

susnux commented Jan 20, 2025

@ShGKme I pushed a commit implementing that feature

Bildschirmaufnahme_20250120_222940.webm

@susnux
Copy link
Contributor Author

susnux commented Jan 20, 2025

For all that want to check the preview netlify:
To make assets (the images work) the output dir has to be different than the input, so we cannot build into styleguide.
We need to fix this.

In the meantime you can just append /build on the URL:
https://deploy-preview-6396--nextcloud-vue-components.netlify.app/build/

return
}

const { height, width } = canvas.value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the canvas size is the way to go, as we do not always render square images. As long as the original image ratio is preserved, then it is fine.

@susnux susnux requested review from artonge and ShGKme January 21, 2025 11:05
@susnux susnux force-pushed the feat/nc-blur-hash branch from 6aceb4b to 4179bb6 Compare January 21, 2025 11:13
@ShGKme
Copy link
Contributor

ShGKme commented Jan 21, 2025

I think using the canvas size is the way to go, as we do not always render square images. As long as the original image ratio is preserved, then it is fine.

@artonge but it is not the canvas or image, but blurhash render size

@artonge
Copy link
Contributor

artonge commented Jan 21, 2025

@artonge but it is not the canvas or image, but blurhash render size

Blurhash render size should keep the same ratio as the original image size, no?

@susnux
Copy link
Contributor Author

susnux commented Jan 21, 2025

but it is not the canvas or image, but blurhash render size

It is, because the blur hash is just (more or less) an encoded gradient.
You need to render it in the correct aspect and one thing that might be browser dependent is how scaling of such data happens. Because if you only render 32px with a gradient and use no interpolation while scaling it will look horrible.

So I think the correct way to go is to render the hash on the canvas size.

@susnux susnux force-pushed the feat/nc-blur-hash branch 2 times, most recently from 6d5bd54 to a255c43 Compare January 21, 2025 11:51
@susnux
Copy link
Contributor Author

susnux commented Jan 21, 2025

BTW Wolt (the author of that algorithm) also does it like this in their react implementation:
https://github.com/woltapp/react-blurhash/blob/master/src/BlurhashCanvas.tsx

@susnux susnux force-pushed the feat/nc-blur-hash branch from a255c43 to 42a22dd Compare January 21, 2025 11:59
@Antreesy Antreesy modified the milestones: 8.23.0, 8.24.0 Feb 13, 2025
This allows to include image previews / placeholders in apps.
Currently something similar is used for the files and for the photos
app.
So this can be used to de-duplicate code.

Co-authored-by: Grigorii K. Shartsev <[email protected]>
Co-authored-by: Ferdinand Thiessen <[email protected]>
Signed-off-by: Ferdinand Thiessen <[email protected]>
@susnux susnux merged commit 9c25a15 into master Feb 28, 2025
24 checks passed
@susnux susnux deleted the feat/nc-blur-hash branch February 28, 2025 13:19
Copy link

backportbot bot commented Feb 28, 2025

The backport to next failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout next
git pull origin next

# Create the new backport branch
git checkout -b backport/6396/next

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick 0ee2517b

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/6396/next

Error: No changes found in backport branch


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

@susnux
Copy link
Contributor Author

susnux commented Feb 28, 2025

/backport to next

Copy link

backportbot bot commented Feb 28, 2025

The backport to next failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout next
git pull origin next

# Create the new backport branch
git checkout -b backport/6396/next

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick 0ee2517b

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/6396/next

Error: No changes found in backport branch


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

Comment on lines +6 to +8
import PQueue from 'p-queue'

const queue = new PQueue({ concurrency: 5 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews backport-request component Component discussion and/or suggestion enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants