# How to compress photo

**URL:** https://community.glideapps.com/t/how-to-compress-photo/36448
**Category:** Ask for Help
**Created:** [December 29, 2021, 6:51am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448 "2021-12-29T06:51:31Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 29, 2021, 6:51am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/1 "2021-12-29T06:51:31Z")

</div>

I am using appscript to turn on the trigger from google sheet to convert to PDF and email to user straightway. and there’s image I include in the page.  
As in the google sheet, this is the page looks like:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/8/a8532443a0fdcd521842b4ddda6e00c6c64e643f.jpeg)

and after the script running:

> **Summary**
>
> var changedFlag = false;
> 
> var TEMPLATESHEET=‘Boom-Report’;
> 
> function emailSpreadsheetAsPDF() {
> 
> // Utilities.sleep(3000); //to pause for 3 seconds . Make sure photo completely upload to google sheet
> 
> DocumentApp.getActiveDocument();
> 
> DriveApp.getFiles();
> 
> // This is the link to my spreadsheet with the Form responses and the Invoice Template sheets
> 
> // Add the link to your spreadsheet here
> 
> // or you can just replace the text in the link between “d/” and “/edit”
> 
> // In my case is the text: 17I8-QDce0Nug7amrZeYTB3IYbGCGxvUj-XMt8uUUyvI
> 
> const ss = SpreadsheetApp.openByUrl(“[https://docs.google.com/spreadsheets/d/1NVJOdFLBAgNFqSHhnHJYybjUlSqhv4hKI\_HXJyhJ88E/edit](https://docs.google.com/spreadsheets/d/1NVJOdFLBAgNFqSHhnHJYybjUlSqhv4hKI_HXJyhJ88E/edit)”);
> 
> // We are going to get the email address from the cell “B7” from the “Invoice” sheet
> 
> // Change the reference of the cell or the name of the sheet if it is different
> 
> const value = ss.getSheetByName(“Source Email-Boom”).getRange(“X3”).getValue();
> 
> const email = value.toString();
> 
> // Subject of the email message
> 
> const subject = ss.getSheetByName(“Source Email-Boom”).getRange(“B3”).getValue();
> 
> ```
> // Email Text. You can add HTML code here - see ctrlq.org/html-mail
> 
> ```
> 
> const body = “Boom Lifts Inspection Report - Sent via Auto Generate PDI Report from Glideapps”;
> 
> // Again, the URL to your spreadsheet but now with “/export” at the end
> 
> // Change it to the link of your spreadsheet, but leave the “/export”
> 
> const url = '[https://docs.google.com/spreadsheets/d/1NVJOdFLBAgNFqSHhnHJYybjUlSqhv4hKI\_HXJyhJ88E/export?’;](https://docs.google.com/spreadsheets/d/1NVJOdFLBAgNFqSHhnHJYybjUlSqhv4hKI_HXJyhJ88E/export?';)
> 
> const exportOptions =
> 
> ```
> 'exportFormat=pdf&format=pdf' + // export as pdf
> 
> '&size=A4' + // paper size letter / You can use A4 or legal
> 
> '&portrait=true' + // orientation portal, use false for landscape
> 
> '&fitw=true' + // fit to page width false, to get the actual size
> 
> '&sheetnames=false&printtitle=false' + // hide optional headers and footers
> 
> '&pagenumbers=false&gridlines=false' + // hide page numbers and gridlines
> 
> '&fzr=false' + // do not repeat row headers (frozen rows) on each page
> 
> '&gid=671631174'; // the sheet's Id. Change it to your sheet ID.
> 
> // You can find the sheet ID in the link bar. 
> 
> ```
> 
> // Select the sheet that you want to print and check the link,
> 
> // the gid number of the sheet is on the end of your link.
> 
> var params = {method:“GET”,headers:{“authorization”:"Bearer "+ ScriptApp.getOAuthToken()}};
> 
> // Generate the PDF file
> 
> var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
> 
> // Send the PDF file as an attachement
> 
> ```
> GmailApp.sendEmail(email, subject, body, {
> 
> htmlBody: body,
> 
> attachments: [{
> 
> fileName: ss.getSheetByName("Source Email-Boom").getRange("B3").getValue().toString() +".pdf",
> 
> content: response.getBytes(),
> 
> mimeType: "application/pdf"
> 
> }]
> 
> });
> 
> ```
> 
> // Save the PDF to Drive. (in the folder) The name of the PDF is going to be the name of the Company (cell B5)
> 
> const nameFile = ss.getSheetByName(“Source Email-Boom”).getRange(“B3”).getValue().toString() +".pdf"
> 
> const folderID = “1ZKWq9jWmeEQlxncuTPHssCFXC3Fidmxn”;
> 
> DriveApp.getFolderById(folderID).createFile(response).setName(nameFile);
> 
> }
> 
> function on\_sheet\_change(event) {
> 
> var sheetname = event.source.getActiveSheet().getName();
> 
> var sheet = event.source.getActiveSheet();
> 
> if (sheetname == ‘Boom-Report’) {
> 
> ```
> emailSpreadsheetAsPDF() ;
> 
> ```
> 
> } else return;
> 
> }

This is the PDF looks like:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/1/116eb7787bb8130098aa93eed221904dc9ea71c5.png)

Turn up only half .

And i believe, this is because the image so large. So, how to compress ?

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 29, 2021, 9:12am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/2 "2021-12-29T09:12:02Z")

</div>

Appreciated if you guys can help me

---

<div class="post-metadata">

### Author: ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)
#### Post date: [December 29, 2021, 2:14pm UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/3 "2021-12-29T14:14:10Z")

</div>

> [@biha](#):
>
> // Utilities.sleep(3000); //to pause for 3 seconds . Make sure photo completely upload to google sheet

I’m not really sure but maybe you could try to run the utilities.sleep(3000)

Right now it is commented out. Take away the //

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 30, 2021, 1:55am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/4 "2021-12-30T01:55:34Z")

</div>

but sleep is to delay. all i need is to compress the photo right .  
Like what for to delay ?

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [December 30, 2021, 2:09am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/5 "2021-12-30T02:09:56Z")

</div>

@Eric_Penn was suggesting that perhaps the PDF is being generated before the images have fully loaded into the template. Your screenshot supports this, as only one image is partially shown. So I suspect he is probably right.

Why don’t you give his suggestion a try?  
You never know, it might work…

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 30, 2021, 2:18am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/6 "2021-12-30T02:18:59Z")

</div>

Yes, i have tried this . Its not work. Same things happen. It turns up half of the image.  
That’s why I put the // .

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [December 30, 2021, 3:17am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/7 "2021-12-30T03:17:39Z")

</div>

I’d still suspect the same problem. Maybe the delay isn’t long enough.  
I can see that you are using an onChange trigger, which means the script will fire as soon as the first change is made in the sheet. Try a longer delay. Try adding a sleep for a full minute.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 30, 2021, 3:28am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/8 "2021-12-30T03:28:44Z")

</div>

Ok i try Utilities.sleep(60000) now , will come back here

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 30, 2021, 7:29am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/9 "2021-12-30T07:29:33Z")

</div>

Still got this  
@Darren_Murphy @Eric_Penn

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/3/8392a3eaf157664d56409d0088cc1fb451a8de1f.png)

I noticed that, even if I download manually through google sheet, same thing happen.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/0/0016a3e6004943bf9488f0ca9a4c0dacfada02fd.png)

---

<div class="post-metadata">

### Author: ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)
#### Post date: [December 30, 2021, 2:02pm UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/10 "2021-12-30T14:02:14Z")

</div>

My appscript experience is limited. You could try adding  
SpreadsheetApp.flush(); before the utilities.sleep

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 1:05am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/11 "2021-12-31T01:05:05Z")

</div>

Noted, i am trying . will come back.

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 1:10am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/12 "2021-12-31T01:10:33Z")

</div>

I’ve tried , PDF Ffiles looks the same, only half appear. Not even half .  
But i noticed after adding SpreadsheetApp.flush(); the file size larger.  
Now was 19MB, before adding was like 11MB.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/2/9221e9b1ba08b669e16202fef7861401a2cd83a5.png)

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 1:19am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/13 "2021-12-31T01:19:14Z")

</div>

Is there any ways to compress photo from the time that user adding up the photo on Glide itself.  
As you know, Whatsapp apps also auto compress the image size. Well, now my user only upload for like 10-15 forms which need photos but the usage of Image & Files near 1 GB.

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/3/032b731748437aa784efabbb04e840fdb43d0fe8.png)

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 6:10am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/14 "2021-12-31T06:10:35Z")

</div>

any ways to auto compress photo ???

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [December 31, 2021, 6:28am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/15 "2021-12-31T06:28:43Z")

</div>

@biha there is no compressing of the uploaded image to glide possible, I’m afraid.

But if you are ok to store the image outside glide then you could use cloudinary and still use the image picker in glide to get hold of the users image.

I have done a similar thing as shown in this post

> [@Photo-location - and images AUTO-UPLOADED to Cloudinary](https://community.glideapps.com/t/photo-location-and-images-auto-uploaded-to-cloudinary/26936):
>
> Main features Upload a photo to Glide and mark it with a location Auto-upload the photos to Cloudinary Resizing and other maniputations of the photo uploaded to Cloudinary Remove the photo from Glide View all the photos uploaded - and directly sourced from Cloudinary account Photo and location saved to both Glide Table and Google Sheets Idea Photo and location is inputted to the glide table “Input…” and data are copied to “Registrations” Photo and location is then cleared from …

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 6:33am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/16 "2021-12-31T06:33:39Z")

</div>

Thanks @Krivo , let me read the threads .

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 6:58am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/17 "2021-12-31T06:58:40Z")

</div>

@Krivo , I’m back

1. I’ve change the Folder Name and Cloud Name

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/5/059f16ca9b0c82c9c07ce9ed01c7b7d83a03cb6e.png)

1. What the location is for ? Naming the photo am i right ?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/7/a756c7da842d6b0f3a654f9e2b4ab4d0caacc99f.png)

1. When I click button “Add Image and Location”, still cannot see the image like you do.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/b/bb9f1d131cfbac615fb62bc725e690e961adab28.png)

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [December 31, 2021, 7:11am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/18 "2021-12-31T07:11:06Z")

</div>

@biha you do not need any location info. It was for another use case that somebody had.

Please check that you gave the correct address of the images in glide.

---

<div class="post-metadata">

### Author: ![Krivo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krivo/32/5363_2.png) [@Krivo](https://community.glideapps.com/u/Krivo)
#### Post date: [December 31, 2021, 7:13am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/19 "2021-12-31T07:13:18Z")

</div>

> [@Photo-location - and images AUTO-UPLOADED to Cloudinary](https://community.glideapps.com/t/photo-location-and-images-auto-uploaded-to-cloudinary/26936/1):
>
> The app gets its assets saved to a specific folder - this can be determined from Google Sheets, sheet General and path to the App image in that sheet. It will be something like:  
> `https://storage.googleapis.com/glide-prod.appspot.com/uploads-v2/xxedxRRB29pZ2kwVHF72/pub/`

This is how you find the correct address of the images uploaded to glide

---

<div class="post-metadata">

### Author: ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)
#### Post date: [December 31, 2021, 7:16am UTC](https://community.glideapps.com/t/how-to-compress-photo/36448/20 "2021-12-31T07:16:23Z")

</div>

> [@Krivo](#):
>
> correct address of the images in glide.

I’m sorry, but where to place the address of the images in Glide?

Here, correct?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/b/7b78e9853ad728e2ad6f1050f9d0bd2f5a16db01.png)

[Next page](https://community.glideapps.com/t/how-to-compress-photo/36448.md?page=2)
