I'm using Apps Script to generate slides containing tiles.
Each tile contain some information, example: name, ID and an image.
To generate each slide & each tile, I'm using a template composed of shapes, each shape to be modified contains a label such as {{label}}
When I find {{image}} shape, I replace the shape by an image.
Images are stored on Drive. I put everything in place to retrieve the blob associated to image but the single operation replaceWithImage takes around 2 seconds (I used console.time/timeEnd just before replaceWithImage and after).
Any idea how to accelerate this ? Initially I was suspecting the search on Drive, but it's around 200ms to look for the file and get the blob.
Related
I have thousands of high-resolution images that I would like to display on my website. I would like to select an image from Google Drive, dynamically tile the image, and display it on the website using OpenSeaDragon. Is that possible? If so, how do I go about it?
Thanks!
Can you get a link to the image on Google Drive? I assume so. Given that, you have a few options:
Paste the URL into https://openseadragon.github.io/openseadragonizer/. This should be plenty fine, as long as your image isn't terribly big; it loads the whole image and then tiles it in memory.
If your image is very large, you can paste its URL into https://zoomhub.net/, where it'll tile it on the server.
If you want to make your own viewer, follow the instructions on https://openseadragon.github.io/docs/. For the image tile source, try https://openseadragon.github.io/examples/tilesource-image/; this is what option 1 above uses.
If you're making your own viewer, and the images are too big to work with the simple image tile source, you'll want something like https://openseadragon.github.io/examples/tilesource-dzi/. You'll need to do the conversion yourself using something from https://openseadragon.github.io/examples/creating-zooming-images/.
I have various Word documents (.docx) saved in Google Drive, everyone has inside a draw composed of text, borders, and a pen-draw, grouped together.
When opened in Google Doc the .docx files to edit, the group appear as a draw composed of the same elements except the pen-draw that is missing.
So I need to solve this, 2 options:
Replace the draw with a saved image
Edit the draw and put inside an image, save&close the draw
Since it is an operation repeated ten times every day I want to find a way to automate this with google appscripts
Any suggestion ?
I would like to be able to, on each individual slide, set a rectangle shape that has a randomly generated gradient, but I can't find any functions to set shape fill to a gradient? Am I just overlooking it, or has it not been implemented?
Issue:
Unfortunately, in the current stage, it seems that there are no methods for setting the gradient color using Google Slides service and Google Slides API. This has already been reported to Google issue tracker as follows.
https://issuetracker.google.com/issues/179455333
https://issuetracker.google.com/issues/191392267
Workaround:
From I would like to be able to, on each individual slide, set a rectangle shape that has a randomly generated gradient, in this case, as the current workaround, how about the following flow?
Manually create multiple shapes by changing the gradient color.
When you want to put a shape on a slide, one of the shapes you have already created is randomly selected and copied, and put on the slide.
In this case, you can change the size of the shape after the shape was put.
I am evaluating Google Sheets with AppScripts for a report generator. The requirements include inserting images from Google Drive. One of the input image has a fix format, which I need to crop. ( So the dimensions of the original image and the dimensions of the crop is known.)
I am looking for a solution to achieve this outcome, but I am struggling. I looked into the following methods:
No image crop function in the Drive API
No image crop ( only resize) for the Sheets OverGridImage object
No image crop for the =IMAGE() function
Manually you can create a drawing, add an image and crop it:
But you can't do this from AppScripts
You can't access the image within the drawing as an OverGridImage object. ( Which would allow you to replace it's image.)
You can use the Slides API replace(imageUrl, crop)
Is it possible to embed/link the slide into the sheet via AppScript?
Is there any other workaround? ( Even if it means creating a new file in drive?)
EDIT: Obviously there is the solution to call an external API, or to use GCP services such as CloudFunctions ( which are not free). However I am hoping for an AppScript solution. ( Or using a compatible JS library.)
I believe your goal as follows.
You want to achieve the crop of image using Google Apps Script.
Issue and workaround:
Unfortunately, in the current stage, there are no methods for directly cropping image using Google Apps Script. This has already been mentioned by your comment. So in this answer, I would like to propose a workaround for cropping image using Google Apps Script.
In this workaround, I use Microsoft Powerpoint and Google Slides. The flow of this workaround is as follows.
Create Microsoft Powerpoint (PPTX data) by setting the page size.
In this case, the width and height of the image left by the crop are set. This is used as a window of image.
When the converted PPTX data is unzipped, the data can be analyzed as the XML data. Fortunately, at Microsoft Docs, the detail specification is published as Open XML. So in this case, Microsoft Docs like XLSX, DOCX and PPTX can be analyzed using XmlService of Google Apps Script. In this workaround, the PPTX data is directly created by including the page size. I think that this method will be also useful for other situations.
When the method of "presentations.create" of Slides API can be correctly used, this is not required. Ref
Convert PPTX data to Google Slides.
Insert the image, that you want to do the crop, to the created Google Slides.
At that time, the crop of "top" and "left" is subtracted from the origin of coordinates. Because the origin of coordinates of Google Slides is the upper-left corner.
The thumbnail image is retrieved using the method of "presentations.pages.getThumbnail" in Slides API.
By above flow, the cropped image can be retrieved as a blob.
In this sample script, an image is cropped using the parameters using Google Apps Script. In this case, the script reflecting above flow is a bit complicated. So here, I would like to introduce the sample script using a Google Apps Script library. Ref Of course, you can see the whole script there.
Sample script:
Before you use this script, please install ImgApp of the Google Apps Script library. Ref And in this case, please enable Drive API and Slides API at Advanced Google services.
function myFunction() {
const id = "###"; // If you want to crop the image on Google Drive, please set the file ID of the image here.
const object = {blob: DriveApp.getFileById(id).getBlob(), crop: {t: 50, b: 100, l: 200, r: 100}};
const blob = ImgApp.editImage(object);
DriveApp.createFile(blob);
}
This sample script crops an image on Google Drive and the cropped image is created to the root folder.
crop: {t: 50, b: 100, l: 200, r: 100} means that the crop size of t, b, l and r are the top, bottom, left and right, respectively. The unit is pixel.
About the maximum image size, you can see it at Limitations for Inserting Images to Google Docs. In this sample script, 25,000,000 pixels^2 is the maximum size of the image.
References:
Understanding the Open XML file formats
XML Service
editImage() in ImgApp
I am trying to create a static map url using google maps api which looks similar to following
It seems like I require to increase the zoom levels and add a path parameter to the url. I have tried to create url like following
http://maps.googleapis.com/maps/api/staticmap?scale=4&format=png32¢er=50.133751,4.833644&zoom=16&size=640x640&markers=color:red%7C50.133751,4.833644&sensor=false&path=color:blue|48.133751,4.833644|50.133751,4.833644&style=feature:road.local
But it is not giving required results, I need to create dynamic urls based on the addresses and lat/lng values provided. I somehow requires to rotate map in such a way so that it always have a vertical road in the middle so that I can draw a path over it. Additionally, I need a bubble which will show a fixed time to reach say 5/1 min.
I am not using any programming language as of now. I am trying to create these urls manually.
Thanks in advance.
EDIT : I don't need to rotate it now. Just wants to show a 1-5 min directions to the given latitude/longtitude/address value and for message bubble, I have created a static image which I can show as an overlay.
Based on your specific needs to show a path and a time from 1 to 5 minutes I would recommend the following:
First of all you need to know that you have two possibilites concerning the label
Use the standard marker and add a label with a length of 1 and [A-Z], [0-9] (so just the time in your case...one to five)
Use a custom icon which already includes the label (in your case this is a option because you just have to create five images containing "2 min" or something)
For the first option I would take the center of two connected points and add a white marker with the label of the route duration like markers=color:white|label:1|52,5210924,13,39181335. Then you will have a white standard marker on your route like this.
For the second option you can change the marker position away from the path (depending on how your label image looks like) and add the image with the correct duration (1.png, 2.png, 3.png,...) like markers=icon:https//your.path/to/image.png|52,5210924,13,39228335. Like this you can include your own image, which would look like this (sorry for the bad image ;-)).
Adding a custom marker icon with a label (in the URL) is sadly not possible.
I think in your case (also when creating it manually) it would be fine to create 5 bubble images and add those as described to your static map. The faster and easier (but not so good looking) way would be the first option, because you could place it right on the path and don't have to create the bubble images.