title: tfjs-react-native from tensor to jpeg
body: <p>There is <code>decodeJpeg</code> from <code>@tensorflow/tfjs-react-native</code> but no <code>encodeJpeg</code>. How to write a tensor into a local jpeg file then?</p>
  <p>I have tried to look at the code and &quot;inverse&quot; the function, I ended up writing:</p>
  <pre class="lang-js prettyprint-override"><code>import * as tf from '@tensorflow/tfjs';
  import * as FileSystem from 'expo-file-system';
  import * as jpeg from 'jpeg-js';
  
  export const encoderJpeg = async (tensor, name) =&gt; {
    // add alpha channel if missing
    const shape = [...tensor.shape]
    shape.pop()
    shape.push(4)
    const tensorWithAlpha = tf.concat([tensor, tensor], [-1]).slice([0], shape)
    
    const array = new Uint8Array(tensorWithAlpha.dataSync())
    const rawImageData = {
      data: array.buffer,
      width: shape[1],
      height: shape[0],
    };
    const jpegImageData = jpeg.encode(rawImageData, 50);
    const imgBase64 = tf.util.decodeString(jpegImageData.data, &quot;base64&quot;)
    const uri = FileSystem.documentDirectory + name;
    await FileSystem.writeAsStringAsync(uri, imgBase64, {
      encoding: FileSystem.EncodingType.Base64,
    });
    return uri
  }
  </code></pre>
  <p>but when I show the images with an <code>&lt;Image /&gt;</code> I see that there are all plain green.</p>