Search code examples
node.jsimage-processingcloudinary

How to transform image via node.js for cloudinary


I am unable to use the API of Cloudinary properly via Node.js. In their documentation it's as easy as this:

cloudinary.v2.uploader.upload("sample.jpg", 
    { eager: [
        { width: 400, height: 300, crop: "pad" }, 
        { width: 260, height: 200, crop: "crop", gravity: "north"} ]}, 
    function(error, result) {console.log(result); });

Unfortunately no image with my eager settings is generated. Only my original image is uploaded. The amount of transformations does increase though even I'm not able to see an image with my settings under Media Library.

Edit: When I call it via URL the image is delivered on the fly! Am I missing something?

Thanks in advance,

Daniel


Solution

  • when using an eager transformation it creates the derived version of the image during the upload process rather than lazily or on the fly. Hence, the transformation is calculated on upload. You can verify this by using the usage API-

    cloudinary.v2.api.usage(function(error, result){console.log(result)});

    You can find the URL that was generated in the response. So for example, your code will generate the following URL-

    http://res.cloudinary.com/<cloud_name>/image/upload/c_crop,g_north,h_200,w_260/v1518429787/sample.jpg