webprogrammer
webprogrammer

Reputation: 790

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

Upvotes: 0

Views: 498

Answers (3)

Juma Kiwaka
Juma Kiwaka

Reputation: 1

What you did is correct. The response from cloudinary should be like below

  {
  asset_id: '7c40a8df3ac00dd62413f9dfb6425d8a',
  public_id: 'rrajl7nl6wxldmbsuouk',
  version: 1590261371,
  version_id: 'ecf752113f7d696e8fd79d1d4aad2176',
  signature: '8bc188c384580c669a77510ec9d93b9a60d45cd9',
  width: 4000,
  height: 6000,
  format: 'jpg',
  resource_type: 'image',
  created_at: '2020-05-23T19:16:11Z',
  tags: [ 'DSC_0884.JPG' ],
  bytes: 298518,
  type: 'upload',
  etag: 'e86babf3cb5cf25249753ac0b5ccca06',
  placeholder: false,
  url: 'http://res.cloudinary.com/pine-date/image/upload/v1590261371/rrajl7nl6wxldmbsuouk.jpg',
  secure_url: 'https://res.cloudinary.com/pine-date/image/upload/v1590261371/rrajl7nl6wxldmbsuouk.jpg',
  original_filename: 'tmp-2-1590261360679DSC_0884',
  original_extension: 'JPG',
  eager: [
    {
      transformation: 'c_fit,e_vibrance:80,h_300,w_400',
      width: 200,
      height: 300,
      bytes: 7325,
      format: 'jpg',
      url: 'http://res.cloudinary.com/pine-date/image/upload/c_fit,e_vibrance:80,h_300,w_400/v1590261371/rrajl7nl6wxldmbsuouk.jpg',
      secure_url: 'https://res.cloudinary.com/pine-date/image/upload/c_fit,e_vibrance:80,h_300,w_400/v1590261371/rrajl7nl6wxldmbsuouk.jpg'
    }
  ]
}

to get the eager transformed url you can access it from result.eager[<transformationIndex>].url

Upvotes: 0

Jeremy Hess
Jeremy Hess

Reputation: 48

I believe you are looking for Cloudinary, not Cloudify. Please re-tag.

Upvotes: 0

Matt Greene
Matt Greene

Reputation: 434

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

Upvotes: 1

Related Questions