exif-images/functions/index.js
/**
 * Convert the output of ImageMagick's `identify -verbose` command to a JavaScript Object.
 */
Convert the output of ImageMagick's `identify -verbose` command to a JavaScript Object.
Convert the output of ImageMagick ' s ` identify - verbose ` command to a JavaScript Object .
function imageMagickOutputToObject(output) {
  let previousLineIndent = 0;
  const lines = output.match(/[^\r\n]+/g);
  lines.shift(); 
  lines.forEach((line, index) => {
    const currentIdent = line.search(/\S/);
    line = line.trim();
    if (line.endsWith(':')) {
      lines[index] = makeKeyFirebaseCompatible(`"${line.replace(':', '":{')}`);
    } else {
      const split = line.replace('"', '\\"').split(': ');
      split[0] = makeKeyFirebaseCompatible(split[0]);
      lines[index] = `"${split.join('":"')}",`;
    }
    if (currentIdent < previousLineIndent) {
      lines[index - 1] = lines[index - 1].substring(0, lines[index - 1].length - 1);
      lines[index] = new Array(1 + (previousLineIndent - currentIdent) / 2).join('}') + ',' + lines[index];
    }
    previousLineIndent = currentIdent;
  });
  output = lines.join('');
  output = '{' + output.substring(0, output.length - 1) + '}'; 
  output = JSON.parse(output);
  console.log('Metadata extracted from image', output);
  return output;
}
function imageMagickOutputToObject ( output ) { let previousLineIndent = 0 ; const lines = output . match ( / [^\r\n]+ / g ) ; lines . shift ( ) ; lines . forEach ( ( line , index ) => { const currentIdent = line . search ( / \S / ) ; line = line . trim ( ) ; if ( line . endsWith ( ':' ) ) { lines [ index ] = makeKeyFirebaseCompatible ( ` ${ line . replace ( ':' , '":{' ) } ` ) ; } else { const split = line . replace ( '"' , '\\"' ) . split ( ': ' ) ; split [ 0 ] = makeKeyFirebaseCompatible ( split [ 0 ] ) ; lines [ index ] = ` ${ split . join ( '":"' ) } ` ; } if ( currentIdent < previousLineIndent ) { lines [ index - 1 ] = lines [ index - 1 ] . substring ( 0 , lines [ index - 1 ] . length - 1 ) ; lines [ index ] = new Array ( 1 + ( previousLineIndent - currentIdent ) / 2 ) . join ( '}' ) + ',' + lines [ index ] ; } previousLineIndent = currentIdent ; } ) ; output = lines . join ( '' ) ; output = '{' + output . substring ( 0 , output . length - 1 ) + '}' ; output = JSON . parse ( output ) ; console . log ( 'Metadata extracted from image' , output ) ; return output ; }
Convert the output of ImageMagick's `identify -verbose` command to a JavaScript Object.
Convert the output of ImageMagick ' s ` identify - verbose ` command to a JavaScript Object .
// Remove First line // remove trailing comma.