Сбой преобразования Imagemagick в облачной функции Firebase Spawn Child Process - PullRequest
0 голосов
/ 12 апреля 2019

Я пытаюсь обрезать изображения до соотношения сторон 12:19 после их загрузки в Firebase Storage с помощью облачной функции, которая прослушивает новые загрузки файлов.

Команда ImageMagic 'convert' работает локально. Однако «порожденный» процесс облачной функции завершается с неизвестной / неописанной ошибкой.

Функция асинхронного ожидания / ожидания, созданная в примере firebase :

const functions = require('firebase-functions');
const cors = require('cors')({ origin: true });
const path = require('path');
const os = require('os');
const spawn = require('child-process-promise').spawn;
const fs = require('fs');

const admin = require('firebase-admin');
admin.initializeApp();

/* ... Some HTTPs Functions ... */

exports.cropWorkerPhoto = functions.storage.object().onFinalize(async (object) => {
  let filePath = object.name;
  let fileName = path.basename(filePath);

  if ( fileName.startsWith('worker_')) {

    let contentType = object.contentType;
    if (!contentType.startsWith('image/')) {
      return console.log('This is not an image.');
    }

    const bucket = admin.storage().bucket(object.bucket);
    const tempFilePath = path.join(os.tmpdir(), fileName);
    await bucket.file(filePath).download( {destination: tempFilePath} );
    console.log(`downloading ${filePath}`);
    console.log(`and storing it in ${tempFilePath}`);

    const workerID = fileName.split('_').pop();
    console.log('Cropping Picture for worker:', workerID);
    await spawn('convert', [tempFilePath, '-gravity', 'center', '-crop', '12:19!', tempFilePath]);

    const croppedFileName = `/${workerID}`;
    const croppedFilePath = path.join(path.dirname(filePath), croppedFileName);

    await bucket.upload(tempFilePath, {
      destination: croppedFilePath,
      metadata: { contentType: contentType },
    });
    console.log('Cropped Picture uploaded to: ', croppedFilePath);
    return fs.unlinkSync(tempFilePath);
  }
  return;
});

А журналы следующие:

2019-04-12T04:05:56.135523524Z D cropWorkerPhoto: Function execution started
2019-04-12T04:05:56.135560721Z D cropWorkerPhoto: Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
2019-04-12T04:05:57.300Z I cropWorkerPhoto: downloading workers/worker_QG5obDng8Q1v6STI0wJJ
2019-04-12T04:05:57.301Z I cropWorkerPhoto: and storing it in /tmp/worker_QG5obDng8Q1v6STI0wJJ
2019-04-12T04:05:57.301Z I cropWorkerPhoto: Cropping Picture for worker: QG5obDng8Q1v6STI0wJJ
2019-04-12T04:05:59.647Z E cropWorkerPhoto: ChildProcessError: `convert /tmp/worker_QG5obDng8Q1v6STI0wJJ -gravity center -crop 12:19! /tmp/worker_QG5obDng8Q1v6STI0wJJ` failed with code 1
    at ChildProcess.<anonymous> (/srv/node_modules/child-process-promise/lib/index.js:132:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:915:16)
    at Socket.stream.socket.on (internal/child_process.js:336:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:561:12)
2019-04-12T04:05:59.741519767Z D cropWorkerPhoto: Function execution took 3607 ms, finished with status: 'error'

Создание миниатюрной функции в примере с базой данных работает хорошо.

Когда я попытался использовать «экстент» вместо «обрезать», ошибка была точно такой же.

Как получить сообщение об ошибке команды 'convert'?

Как увидеть версию ImageMagick, установленную на серверах Firebase?

...