mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 02:53:44 +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
63 lines
1.0 KiB
JSON
63 lines
1.0 KiB
JSON
{
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"id": {
|
|
"type": "integer"
|
|
},
|
|
"url": {
|
|
"type": "string"
|
|
},
|
|
"original_filename": {
|
|
"type": "string"
|
|
},
|
|
"filesize": {
|
|
"type": "integer"
|
|
},
|
|
"width": {
|
|
"type": "integer"
|
|
},
|
|
"height": {
|
|
"type": "integer"
|
|
},
|
|
"thumbnail_width": {
|
|
"type": "integer"
|
|
},
|
|
"thumbnail_height": {
|
|
"type": "integer"
|
|
},
|
|
"extension": {
|
|
"type": "string"
|
|
},
|
|
"short_url": {
|
|
"type": "string"
|
|
},
|
|
"short_path": {
|
|
"type": "string"
|
|
},
|
|
"retain_hours": {
|
|
"type": ["string", "null"]
|
|
},
|
|
"human_filesize": {
|
|
"type": "string"
|
|
},
|
|
"dominant_color": {
|
|
"type": ["string", "null"]
|
|
}
|
|
},
|
|
"required": [
|
|
"id",
|
|
"url",
|
|
"original_filename",
|
|
"filesize",
|
|
"width",
|
|
"height",
|
|
"thumbnail_width",
|
|
"thumbnail_height",
|
|
"extension",
|
|
"short_url",
|
|
"short_path",
|
|
"retain_hours",
|
|
"human_filesize"
|
|
]
|
|
}
|