Skip to content

The package includes simple class improving your work with PNG images within AppsScript environment

License

Notifications You must be signed in to change notification settings

szymwi/PNGUtility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PNGUtility

The package includes simple class improving your work with PNG images within AppsScript environment

Review

PNGUtility provides Image class - it’s simple but improves your work with PNG images within AppsScript environment. It’s way faster than workaround with SlidesApp interface.

Implements:

The Image class provides following operations:

  • crop - Image canvas cropping and stretching
  • scale - Image scaling (with bilinear interpolation)
  • toBase64/ImageFromBase64 To/From Base64 conversion

and others...

Installation

Install as AppsScript library using following ID:

1uo7WeG0VaP4nzmgw_JfCs-GwkDsxfVbOyG3DhzP9HIaSE9i-h1u0M90A

Note: The library is running only in V8 environment.

Sample

function demo() {
  const png = UrlFetchApp
    .fetch("https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png")
    .getAs("image/png")
    .getBytes() //just Google logo

  const klass = PNGUtility.newImage(png)

  const clipping = klass.crop(0, 740, 0, 320).scale(0.3) // some manipulations...

  DriveApp.createFile(clipping.toBlob('Goo')) // Google became small Goo immediately

  //Cell Image? Why not
  let cimg
  cimg = SpreadsheetApp.newCellImage()
  cimg.setSourceUrl(
    "data:image/png;base64," +
    Utilities.base64Encode(klass.toByteStream())
  )
  SpreadsheetApp.getActiveSpreadsheet().getRange('a1').setValue(cimg.build())
}

About

The package includes simple class improving your work with PNG images within AppsScript environment

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published