title: How to get the dimensions of an image from firebase storage in firebase functions?
body: <p>I have an app having firebase back-end. and when i made i didn't thought about the dimensions of images as if they ll be useful in future so i just kept the images as they are and kept their URLs in firestore.</p>
  
  <p>But now i m in need of dimensions of images before showing them to user so i have thought of making a function that i ll execute only once in order to set the files with their dimension in firestore and i ll also add some client side code in order to get the dimensions before uploading them.</p>
  
  <p>So i have tried almost everything to get the file dimensions in functions but couldn't do it. </p>
  
  <h3>sample[abstract code]</h3>
  
  <p>this code works in node.js but fails in firebase functions</p>
  
  <pre><code>    const fs = require('fs')
      const request = require('request')
      import sizeOf from 'image-size'
      const FIRE = 'https://firebasestorage.googleapis.com/file....'
      const FILE = 'file.jpg';
  
      request.head(FIRE, (err, res, body) =&gt; {
          request(FIRE)
              .pipe(fs.createWriteStream(FILE))
              .on('close', () =&gt; {
                  sizeOf(FILE, (err1, dimensions) =&gt; {
                      const result = {
                          "width": dimensions.width,
                          "height": dimensions.height
                      }
                      console.log(dimensions.width, dimensions.height);
                      fs.unlinkSync(FILE);
                      response.setHeader('Content-Type', 'application/json');
                      const responseData = {
                          'Error': false,
                          'Message': "result : " + result
                      };
                      response.send(JSON.stringify(responseData));
                  })
              })
      })
  </code></pre>
  
  <p>help me if someone knows something about this!</p>
  
  <p>and moreover also tell me about how firebase keeps images, i mean in what manner ? whenever i open the url it doesnt show me the image instead it just downloads the image unline other urls on random websites.</p>
  
  <p>I have got a trick to do it. It is quite prone to error, but will work for sure : </p>
  
  <p>get all the urls of images using an api and do the stuff locally using node.js and post the result to another api, which will then feed the data to firestore ?</p>