mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 09:33:37 +08:00
d0243f741e
We previously had a system which would generate a 10x10px preview of images and add their URLs in a data-small-upload attribute. The client would then use that as the background-image of the `<img>` element. This works reasonably well on fast connections, but on slower connections it can take a few seconds for the placeholders to appear. The act of loading the placeholders can also break or delay the loading of the 'real' images. This commit replaces the placeholder logic with a new approach. Instead of a 10x10px preview, we use imagemagick to calculate the average color of an image and store it in the database. The hex color value then added as a `data-dominant-color` attribute on the `<img>` element, and the client can use this as a `background-color` on the element while the real image is loading. That means no extra HTTP request is required, and so the placeholder color can appear instantly. Dominant color will be calculated: 1. When a new upload is created 2. During a post rebake, if the dominant color is missing from an upload, it will be calculated and stored 3. Every 15 minutes, 25 old upload records are fetched and their dominant color calculated and stored. (part of the existing PeriodicalUpdates job) Existing posts will continue to use the old 10x10px placeholder system until they are next rebaked |
||
---|---|---|
.. | ||
schemas | ||
shared | ||
backups_spec.rb | ||
badges_spec.rb | ||
categories_spec.rb | ||
groups_spec.rb | ||
invites_spec.rb | ||
notifications_spec.rb | ||
posts_spec.rb | ||
private_messages_spec.rb | ||
search_spec.rb | ||
site_spec.rb | ||
tags_spec.rb | ||
topics_spec.rb | ||
uploads_spec.rb | ||
user_badges_spec.rb | ||
users_spec.rb |