I'm writing an Google Docs add-on. What it does: It takes images out of a Google Drive folder and places it in a Google Doc. ... Well, that's what it does in a nutshell ;-)
I wonder if there is a way to find out the image orientation (landscape/portrait) BEFORE inserting it in the Google Doc. (Once it is inserted, it is not a problem, but I need to figure it out BEFORE the image is inserted so the script runs faster.)
So what I need is something like this:
function getImagesFromFolder(ID){
DriveApp.getFolderById(ID).getFiles();
var mimetypes = ["image/png","image/jpeg","image/gif","image/bmp"];
var images = [];
while (files.hasNext())
{
var file = files.next();
if( mimetypes.indexOf(file.getMimeType()) != -1)
{
var imageObject = {};
imageObject.fileAsJpeg = file.getBlob().getAs("image/jpeg")
imageObject.orientation = getImagefileOrientation(file)
//Here is the issue! I need a 'getImageFileOrientation-function' that returns 'landscape' or 'portrait'
images.push(imageObject);
}
}
return images;
}
//------Later on I will be using----------
for (var i = 0;i<images.length;i++)
{
if (images[i].orientation == 'portrait')
{
// some code that rotates the image when it is inserted in the Google Doc. Not the problem.
}
else
{
googleDocBody.insertImage(images[i].fileAsJpeg); //Not the problem
}
}
Thanks in advance!
Jasper