17 add colorbar to gif
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import geemap
import os
import geemap
import os
In [3]:
Copied!
# geemap.update_package()
# geemap.update_package()
Download a GIF¶
In [4]:
Copied!
from geemap import *
from geemap import *
In [5]:
Copied!
url = 'https://i.imgur.com/MSde1om.gif'
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
download_from_url(url, out_file_name='temp.gif', out_dir=out_dir)
url = 'https://i.imgur.com/MSde1om.gif'
out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
download_from_url(url, out_file_name='temp.gif', out_dir=out_dir)
Downloading https://i.imgur.com/MSde1om.gif ... Data downloaded to: /home/runner/Downloads/temp.gif
In [6]:
Copied!
in_gif = os.path.join(out_dir, 'temp.gif')
show_image(in_gif)
in_gif = os.path.join(out_dir, 'temp.gif')
show_image(in_gif)
Get image URLs¶
In [7]:
Copied!
noaa_logo = 'https://bit.ly/3ahJoMq'
ee_logo = 'https://i.imgur.com/Qbvacvm.png'
noaa_logo = 'https://bit.ly/3ahJoMq'
ee_logo = 'https://i.imgur.com/Qbvacvm.png'
Set output GIF path¶
In [8]:
Copied!
out_gif = os.path.join(out_dir, 'output.gif')
out_gif = os.path.join(out_dir, 'output.gif')
Add images to GIF¶
In [9]:
Copied!
add_image_to_gif(
in_gif, out_gif, in_image=noaa_logo, xy=('2%', '80%'), image_size=(80, 80)
)
add_image_to_gif(
in_gif, out_gif, in_image=noaa_logo, xy=('2%', '80%'), image_size=(80, 80)
)
cannot identify image file <_io.BytesIO object at 0x7f4fc899e590>
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [9], in <cell line: 1>() ----> 1 add_image_to_gif( 2 in_gif, out_gif, in_image=noaa_logo, xy=('2%', '80%'), image_size=(80, 80) 3 ) File ~/.local/lib/python3.9/site-packages/geemap/timelapse.py:585, in add_image_to_gif(in_gif, out_gif, in_image, xy, image_size, circle_mask) 582 except Exception as e: 583 print(e) --> 585 logo_raw_size = logo_raw_image.size 587 ratio = max( 588 logo_raw_size[0] / image_size[0], 589 logo_raw_size[1] / image_size[1], 590 ) 591 image_resize = (int(logo_raw_size[0] / ratio), int(logo_raw_size[1] / ratio)) AttributeError: 'NoneType' object has no attribute 'size'
In [10]:
Copied!
add_image_to_gif(
out_gif, out_gif, in_image=ee_logo, xy=('13%', '79%'), image_size=(85, 85)
)
add_image_to_gif(
out_gif, out_gif, in_image=ee_logo, xy=('13%', '79%'), image_size=(85, 85)
)
The input gif file does not exist.
Display output GIF¶
In [11]:
Copied!
show_image(out_gif)
show_image(out_gif)
Create a colorbar¶
In [12]:
Copied!
width = 250
height = 30
palette = ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']
labels = [-40, 35]
colorbar = create_colorbar(
width=width,
height=height,
palette=palette,
vertical=False,
add_labels=True,
font_size=20,
labels=labels,
)
width = 250
height = 30
palette = ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']
labels = [-40, 35]
colorbar = create_colorbar(
width=width,
height=height,
palette=palette,
vertical=False,
add_labels=True,
font_size=20,
labels=labels,
)
In [13]:
Copied!
show_image(colorbar)
show_image(colorbar)
Add colorbar to GIF¶
In [14]:
Copied!
add_image_to_gif(
out_gif, out_gif, in_image=colorbar, xy=('69%', '89%'), image_size=(250, 250)
)
add_image_to_gif(
out_gif, out_gif, in_image=colorbar, xy=('69%', '89%'), image_size=(250, 250)
)
The input gif file does not exist.
In [15]:
Copied!
show_image(out_gif)
show_image(out_gif)
Last update:
2022-03-14