Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions slides/snippets/slides_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,16 @@ def create_textbox_with_text(self, presentation_id, page_id):

def create_image(self, presentation_id, page_id, image_file_path,
image_mimetype):
slides_service = self.service
drive_service = self.drive_service
slides_service = self.service
# [START slides_create_image]
# Temporarily upload a local image file to Drive, in order to obtain a
# URL for the image. Alternatively, you can provide the Slides service
# a URL of an already hosted image.
upload = drive_service.files().create(
body={'name': 'My Image File', 'mimeType': image_mimetype},
media_body=image_file_path).execute()
file_id = upload.get('id')

# Obtain a URL for the image.
image_url = '%s&access_token=%s' % (
drive_service.files().get_media(
fileId=file_id).uri, self.credentials.access_token)
#
# We will use an existing image under the variable: IMAGE_URL.
IMAGE_URL = ('https://www.google.com/images/branding/'
'googlelogo/2x/googlelogo_color_272x92dp.png')

# Create a new image, using the supplied object ID,
# with content downloaded from image_url.
Expand All @@ -160,7 +155,7 @@ def create_image(self, presentation_id, page_id, image_file_path,
requests.append({
'createImage': {
'objectId': image_id,
'url': image_url,
'url': IMAGE_URL,
'elementProperties': {
'pageObjectId': page_id,
'size': {
Expand Down Expand Up @@ -188,8 +183,6 @@ def create_image(self, presentation_id, page_id, image_file_path,
print('Created image with ID: {0}'.format(
create_image_response.get('objectId')))

# Remove the temporary image file from Drive.
drive_service.files().delete(fileId=file_id).execute()
# [END slides_create_image]
return response

Expand Down