'Replace text in body in google doc with an image (PNG format)

I need to replace a text in google doc for an image (PNG format). I tried sevaral ways but it seems that there is a problem getting blob from a PNG file (is mandatory that the format is PNG because is generated from a signature in Appsheet). I tried getAs('image/jpeg') but it didnt work

function myFunction() {
  var replaceTextToImage = function(body, searchText, image, width) {
    var next = body.findText(searchText);
    if (!next) return;
    var r = next.getElement();
    r.asText().setText("");
    var img = r.getParent().asParagraph().insertInlineImage(0, image);
    if (width && typeof width == "number") {
    var w = img.getWidth();
    var h = img.getHeight();
    img.setWidth(width);
    img.setHeight(width * h / w);
    }
    return next;
  };
var folder = DriveApp.getFolderById('1uMkFrLzT6rrGngS4f7vWUJCK8GJwrvF6');
var files = folder.getFilesByName(imagen);
var fileId = files.hasNext() ? files.next().getId() : "";
Logger.log(fileId)
var image = DriveApp.getFileById(fileId).getBlob(;
do {
  var next = replaceTextToImage(body,'{{firma}}', image, 200);
} while (next);
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source