diff --git a/ImgApp.js b/ImgApp.js index 78767a1..0dbfb1a 100644 --- a/ImgApp.js +++ b/ImgApp.js @@ -15,7 +15,7 @@ * @return {Object} JSON object {identification: [png, jpg, gif and bmp], width: [pixel], height: [pixel], filesize: [bytes]} */ function getSize(blob) { - return new ImgApp().GetSize(blob) + return new ImgApp().GetSize(blob); } /** @@ -32,7 +32,7 @@ function getSize(blob) { * @return {Object} JSON object {blob: [blob], originalwidth: ###, originalheight: ###, resizedwidth: ###, resizedheight: ###} */ function doResize(fileId, width) { - return new ImgApp().DoResize(fileId, width) + return new ImgApp().DoResize(fileId, width); } /** @@ -50,7 +50,7 @@ function doResize(fileId, width) { * @return {Object} JSON object id,mimeType,name,thumbnailVersion,thumbnailLink */ function updateThumbnail(imgFileId, srcFileId) { - return new ImgApp().UpdateThumbnail(imgFileId, srcFileId) + return new ImgApp().UpdateThumbnail(imgFileId, srcFileId); } /** @@ -63,7 +63,7 @@ function updateThumbnail(imgFileId, srcFileId) { * @return {Object} Blob of result image. */ function editImage(object) { - return new ImgApp().EditImage(object) + return new ImgApp().EditImage(object); } ; (function(r) { @@ -161,7 +161,7 @@ function editImage(object) { }; cropImage = function(obj_) { - var _, b, croppedBlob, height, l, object, presentationId, ref, rs, rsHeight, rsWidth, setHeight, setL, setT, setWidth, size, slide, slides, t, unit, width; + var _, b, croppedBlob, height, l, object, presentationId, ref, rs, setHeight, setL, setT, setWidth, size, slide, slides, t, unit, width; unit = obj_.hasOwnProperty("unit") && typeof obj_.unit === "string" ? obj_.unit : "pixel"; size = this.GetSize(obj_.blob); if (size.width * size.height > 25000000) { @@ -196,15 +196,10 @@ function editImage(object) { setT = obj_.unit === "pixel" ? pixelToPt.call(this, t) : t; _ = slide.insertImage(obj_.blob, -setL, -setT, setWidth, setHeight); slides.saveAndClose(); - rsWidth = size.width - (obj_.unit === "point" ? ptToPixel.call(this, l) : l) - (obj_.unit === "point" ? ptToPixel.call(this, r) : r); - rsHeight = size.height - (obj_.unit === "point" ? ptToPixel.call(this, t) : t) - (obj_.unit === "point" ? ptToPixel.call(this, b) : b); + rs = size.width - (obj_.unit === "point" ? ptToPixel.call(this, l) : l) - (obj_.unit === "point" ? ptToPixel.call(this, r) : r); if (obj_.hasOwnProperty("outputWidth") && obj_.outputWidth > 0 && obj_.outputWidth <= 1600) { - rsWidth = obj_.unit === "point" ? ptToPixel.call(this, obj_.outputWidth) : obj_.outputWidth; + rs = obj_.unit === "point" ? ptToPixel.call(this, obj_.outputWidth) : obj_.outputWidth; } - if (obj_.hasOwnProperty("outputHeight") && obj_.outputHeight > 0 && obj_.outputHeight <= 1600) { - rsHeight = obj_.unit === "point" ? ptToPixel.call(this, obj_.outputHeight) : obj_.outputHeight; - } - rs = Math.max(rsWidth, rsHeight); croppedBlob = getImageFromSlide.call(this, presentationId, slide.getObjectId(), rs, obj_.blob.getName()); DriveApp.getFileById(presentationId).setTrashed(true); return croppedBlob; @@ -263,7 +258,7 @@ function editImage(object) { } img4thumb = DriveApp.getFileById(imgFileId_); mime = img4thumb.getMimeType(); - if (mime !== "image/png" && mime !== "image/gif" && mime !== "image/hpeg") { + if (mime !== "image/png" && mime !== "image/gif" && mime !== "image/jpeg") { throw new Error("The image format (" + mime + ") cannot be used for thumbnail."); } metadata = { @@ -275,7 +270,7 @@ function editImage(object) { } }; fields = "id,mimeType,name,thumbnailVersion,thumbnailLink"; - url = "https://www.googleapis.com/upload/drive/v3/files/" + srcFileId_ + "?uploadType=multipart&fields=" + encodeURIComponent(fields); + url = "https://www.googleapis.com/upload/drive/v3/files/" + srcFileId_ + "?uploadType=multipart&supportsAllDrives=true&fields=" + encodeURIComponent(fields); boundary = "xxxxxxxxxx"; data = "--" + boundary + "\r\n"; data += "Content-Disposition: form-data; name=\"metadata\"\r\n"; @@ -294,7 +289,7 @@ function editImage(object) { ImgApp.prototype.DoResize = function(fileId, width) { var blob, e, headers, method, mimetype, n, res, resized, rs, thumbUrl, turl, url; try { - url = "https://www.googleapis.com/drive/v3/files/" + fileId + "?fields=thumbnailLink%2CmimeType"; + url = "https://www.googleapis.com/drive/v3/files/" + fileId + "?supportsAllDrives=true&fields=thumbnailLink%2CmimeType"; method = "get"; headers = { "Authorization": "Bearer " + ScriptApp.getOAuthToken() diff --git a/README.md b/README.md index c38cfce..42ed3a6 100644 --- a/README.md +++ b/README.md @@ -415,4 +415,8 @@ This is a sample script for reducing the image data size using Google Apps Scrip Updated by [this pull request](https://github.com/tanaikech/ImgApp/pull/11). +- v1.3.2 (January 27, 2023) + + Updated by [this report](https://github.com/tanaikech/ImgApp/issues/13). From this version, the shared Drive can be used. + [TOP](#top)