Google Script to replace image background color?

571 Views Asked by At

Looking to automate the tedious clicking to change the backround of my PNG images from white to transparent.

The images reside in Google Drive, and as new images are submitted I have to make it transparent, each time, again. There's got to be a better way!

1

There are 1 best solutions below

0
Alan Wells On BEST ANSWER

I don't see any way to use that website with code. That website has what it calls an API, but it looks like it's nothing more than a link. You could use something like AutoIt, to reproduce the keystrokes that you manually do.

AutoIt website

If there was an online picture editor that had an API that would receive HTTP Requests, Apps Script can send and receive HTTP Requests.

Google Documentation urlFetch

But the online picture editor would also need to read your files from your Google Account.

HTML does have a canvas tag, that you can manipulate pictures with, but Apps Script currently doesn't work with the canvas HTML tag the last I knew.

You can access your Google Drive with Apps Script, and get files, but then you'd need to either send the file out somewhere, or process it yourself, just like that online picture editor does. If Caja would allow the HTML Canvas tag to work with HTML Service, there might be a way to automate what you want.

I created a way to re-size pictures with the Canvas tag, but it wouldn't work with Apps Script HTML Service.