メインコンテンツにスキップ

ImgApp

This is a library of image tools for Google Apps Script.

AI Summary

ImgApp

Image tools library for Google Apps Script.

Target Users

Intermediate GAS developers needing image size retrieval, resizing, thumbnail updates, and editing on Drive.

Problems Solved

GAS lacks direct methods for image sizing, resizing, editing, requiring efficient workarounds.

Script ID

  1. In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
  2. "ImgApp" will appear in the search results
  3. Select the latest version (highest number) from "Version" dropdown
  4. Click "Add"

Tags

Main Features
1
Fast sizing

Retrieves image width/height from BMP,GIF,PNG,JPG at binary level with low cost, faster than Docs method.

2
Image resize

Resizes images/docs via Drive thumbnails by width. Max original size or 1024px width, aspect ratio kept.

3
Thumbnail update

Updates Drive file thumbnails with custom images. Effective for ZIP files without auto-generated thumbs.

Examples

Main Functions

FunctionDescription
ImgApp.getSize(blob)Gets image size info.
ImgApp.doResize(fileId, width)Resizes image by width.
ImgApp.editImage(object)Crops/merges images.

Examples

Get image size
/**
 * 画像サイズ取得
 * ・ファイルBlob取得: DriveApp.getFileById(fileId).getBlob();
 * ・サイズ情報取得: ImgApp.getSize(blob);
 * ・幅と高さ参照: res.width, res.height;
 */
function getImageSize(fileId) {
  var blob = DriveApp.getFileById(fileId).getBlob();
  var res = ImgApp.getSize(blob);
  var width = res.width;
  var height = res.height;
}

Resize image
/**
 * 画像リサイズ
 * ・ファイルIDと幅指定: ImgApp.doResize(fileId, width);
 * ・リサイズBlob取得: res.blob;
 * ・幅高さ確認: res.resizedwidth, res.resizedheight;
 */
function resizeImage(fileId, width) {
  var res = ImgApp.doResize(fileId, width);
  var resizedWidth = res.resizedwidth;
  var resizedHeight = res.resizedheight;
  DriveApp.createFile(res.blob.setName('resized'));
}

Crop image
/**
 * 画像トリミング
 * ・オブジェクト設定: {blob, unit: 'pixel', crop: {t,b,l,r}, outputWidth};
 * ・編集実行: ImgApp.editImage(object);
 * ・出力Blob取得: blob;
 */
function cropImage(imageBlob) {
  const object = {
    blob: imageBlob,
    unit: "pixel",
    crop: { t: 50, b: 100, l: 200, r: 100 },
    outputWidth: 800,
  };
  const blob = ImgApp.editImage(object);
  // DriveApp.createFile(blob);
}

Sample Code

Post a Sample

No sample codes for this library yet

Be the first to post a sample!

Post a Sample