gianlucadelgobbo / avnode

4 stars 7 forks source link

Thumbnail handling #71

Open gianlucadelgobbo opened 8 years ago

gianlucadelgobbo commented 8 years ago

there was a function that accordingly to the config was lookig for a size format if there wasnt he create it if there isnt the image was taking the default image.

gianlucadelgobbo commented 8 years ago

app/server/helper/media.js line 44 Almost done but the crop callback arrives when the image is still not available, solution?

alappe commented 8 years ago

From a quick glance, the solution isn't that easy.

Since the imagemagick functions are are asynchronous, the getFileFormat function has to be async as well. Changing that is simple, but the usage seems to be inline in jade, and there we cannot use the resulting async function.

So one way would be to get the metadata and do cropping on upload, not on display. The other way could be prepare all data such as this before the view is rendered, which would make the first view slow (since images will need to be resized).

gianlucadelgobbo commented 8 years ago

yes, server side could be very slow and we need to put a lot of code to make this check on every query in node, one single big event in node could have more then 1000 images, nested in different locations

Another solution could be a js client side for this very rare case

document.addEventListener('DOMContentLoaded', function () {
    var img = document.getElementById("img-#{result.permalink}");
    if (!img.complete || typeof img.naturalWidth !== "undefined" && img.naturalWidth === 0) {
        img.src += "?" + new Date().getTime();
        console.log("reload");
    }
}, false);

Some more examples here http://stackoverflow.com/questions/92720/jquery-javascript-to-replace-broken-images

gianlucadelgobbo commented 8 years ago

Formats are here, in every item of the sections config/default.json

      "thumbnails": {
        "detail":{"w":1140,"h":641,"default":"event.jpg"},
        "list":{"w":263,"h":148,"default":"event.jpg"}
      }
stefanisak commented 8 years ago

IMHO we should store the original file on upload and resize it later based on configuration. Resizing during upload solves the performance/async issue, but makes it hard to adjust the layout once different dimensions are required.

I'll try to find a solution based on your configs and @alappe suggests and come back here.

gianlucadelgobbo commented 8 years ago

For sure we do it in upload, but this is just for safety reason, noo?