Skip to content

Commit

Permalink
replace getsize by getbbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jburel committed Jan 10, 2024
1 parent df8830f commit ab5df60
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions omero/figure_scripts/Movie_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def createmovie_figure(conn, pixel_ids, t_indexes, z_start, z_end, width,
col_count = min(max_col_count, len(rendered_images))
row_count = int(math.ceil(len(rendered_images) / col_count))
font = image_utils.get_font(width // 12)
font_height = font.getsize("Textq")[1]
font_height = font.getbbox("Textq")[3]
canvas_width = ((width + spacer) * col_count) + spacer
canvas_height = row_count * (spacer // 2 + font_height +
spacer + height)
Expand All @@ -211,7 +211,7 @@ def createmovie_figure(conn, pixel_ids, t_indexes, z_start, z_end, width,
if t_index >= size_t:
continue
time = time_labels[t]
text_w = font.getsize(time)[0]
text_w = font.getbbox(time)[2]
inset = (width - text_w) // 2
textdraw = ImageDraw.Draw(canvas)
textdraw.text((text_x+inset, text_y), time, font=font,
Expand Down Expand Up @@ -295,7 +295,7 @@ def add_left_labels(panel_canvas, image_labels, row_index, width, spacer):
mode = "RGB"
white = (255, 255, 255)
font = image_utils.get_font(width/12)
text_height = font.getsize("Sampleq")[1]
text_height = font.getbbox("Sampleq")[3]
text_gap = spacer / 2

# find max number of labels
Expand Down
6 changes: 3 additions & 3 deletions omero/figure_scripts/Movie_ROI_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_roi_movie_view(re, query_service, pixels, time_shape_map,
row_count += 1
col_count = max_columns
font = image_utils.get_font(font_size)
text_height = font.getsize("Textq")[1]
text_height = font.getbbox("Textq")[3]
# no spaces around panels
canvas_width = ((panel_width + spacer) * col_count) - spacer
row_height = rendered_images[0].size[1] + spacer + text_height
Expand All @@ -221,7 +221,7 @@ def get_roi_movie_view(re, query_service, pixels, time_shape_map,
col = 0
for i, img in enumerate(rendered_images):
label = time_labels[i]
indent = (panel_width - (font.getsize(label)[0])) // 2
indent = (panel_width - (font.getbbox(label)[2])) // 2
draw.text((px+indent, text_y), label, font=font, fill=(0, 0, 0))
image_utils.paste_image(img, canvas, px, panel_y)
if col == (col_count - 1):
Expand Down Expand Up @@ -381,7 +381,7 @@ def get_split_view(conn, image_ids, pixel_ids, merged_indexes, merged_colours,
elif width > 200:
font_size = 16
font = image_utils.get_font(font_size)
text_height = font.getsize("Textq")[1]
text_height = font.getbbox("Textq")[3]
max_count = 0
for row in image_labels:
max_count = max(max_count, len(row))
Expand Down
10 changes: 5 additions & 5 deletions omero/figure_scripts/ROI_Split_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,

# now assemble the roi split-view canvas
font = image_utils.get_font(fontsize)
text_height = font.getsize("Textq")[1]
text_height = font.getbbox("Textq")[3]
top_spacer = 0
if show_top_labels:
if merged_names:
Expand All @@ -247,7 +247,7 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,
draw = ImageDraw.Draw(canvas)
for i, index in enumerate(split_indexes):
label = channel_names.get(index, index)
indent = (panel_width - (font.getsize(label)[0])) // 2
indent = (panel_width - (font.getbbox(label)[2])) // 2
# text is coloured if channel is not coloured AND in the merged image
rgb = (0, 0, 0)
if index in merged_colours:
Expand Down Expand Up @@ -275,12 +275,12 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,
name = channel_names[index]
else:
name = str(index)
comb_text_width = font.getsize(name)[0]
comb_text_width = font.getbbox(name)[2]
inset = int((panel_width - comb_text_width) / 2)
draw.text((px + inset, text_y), name, font=font, fill=rgb)
text_y = text_y - text_height
else:
comb_text_width = font.getsize("Merged")[0]
comb_text_width = font.getbbox("Merged")[2]
inset = int((panel_width - comb_text_width) / 2)
draw.text((px + inset, text_y), "Merged", font=font,
fill=(0, 0, 0))
Expand Down Expand Up @@ -431,7 +431,7 @@ def get_split_view(conn, image_ids, pixel_ids, split_indexes, channel_names,
elif width > 200:
fontsize = 16
font = image_utils.get_font(fontsize)
text_height = font.getsize("Textq")[1]
text_height = font.getbbox("Textq")[3]
max_count = 0
for row in image_labels:
max_count = max(max_count, len(row))
Expand Down
8 changes: 4 additions & 4 deletions omero/figure_scripts/Split_View_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes,
font = image_utils.get_font(fontsize)
mode = "RGB"
white = (255, 255, 255)
text_height = font.getsize("Textq")[1]
text_height = font.getbbox("Textq")[3]

# if adding text to the left, write the text on horizontal canvas, then
# rotate to vertical (below)
Expand Down Expand Up @@ -442,7 +442,7 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes,
py = top_text_height + spacer - (text_height + text_gap)
for index in split_indexes:
# calculate the position of the text, centered above the image
w = font.getsize(channel_names[index])[0]
w = font.getbbox(channel_names[index])[2]
inset = int((width - w) // 2)
# text is coloured if channel is grey AND in the merged image
rgba = (0, 0, 0, 255)
Expand All @@ -465,12 +465,12 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes,
if rgba == (255, 255, 255, 255): # if white (unreadable)
rgba = (0, 0, 0, 255) # needs to be black!
name = channel_names[index]
comb_text_width = font.getsize(name)[0]
comb_text_width = font.getbbox(name)[2]
inset = int((width - comb_text_width) // 2)
draw.text((px + inset, py), name, font=font, fill=rgba)
py = py - text_height
else:
comb_text_width = font.getsize("Merged")[0]
comb_text_width = font.getbbox("Merged")[2]
inset = int((width - comb_text_width) // 2)
px = px + inset
draw.text((px, py), "Merged", font=font, fill=(0, 0, 0))
Expand Down
14 changes: 7 additions & 7 deletions omero/figure_scripts/Thumbnail_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids,
fontsize = (length // 10) + 5
font = get_font(fontsize)
if left_label:
text_width, text_height = font.getsize(left_label)
text_width, text_height = font.getbbox(left_label)[2:]
left_space = spacing + text_height + spacing
if top_label:
text_width, text_height = font.getsize(top_label)
text_width, text_height = font.getbbox(top_label)[2:]
top_space = spacing + text_height + spacing
min_width = left_space + text_width + spacing

Expand All @@ -168,7 +168,7 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids,
label_size = (label_canvas_width, label_canvas_height)
text_canvas = Image.new(mode, label_size, bg)
draw = ImageDraw.Draw(text_canvas)
text_width = font.getsize(left_label)[0]
text_width = font.getbbox(left_label)[2]
text_x = (label_canvas_width - text_width) // 2
draw.text((text_x, spacing), left_label, font=font, fill=text_color)
vertical_canvas = text_canvas.rotate(90)
Expand Down Expand Up @@ -297,7 +297,7 @@ def paint_dataset_canvas(conn, images, title, tag_ids=None,
# set-up fonts
fontsize = length/7 + 5
font = get_font(fontsize)
text_height = font.getsize("Textq")[1]
text_height = font.getbbox("Textq")[3]
top_spacer = spacing + text_height
left_spacer = spacing + text_height

Expand Down Expand Up @@ -372,11 +372,11 @@ def paint_dataset_canvas(conn, images, title, tag_ids=None,
'showSubsetLabels': show_subset_labels})

# Find the indent we need
max_tag_name_width = max([font.getsize(ts['tagText'])[0]
max_tag_name_width = max([font.getbbox(ts['tagText'])[2]
for ts in toptag_sets])
if show_untagged:
max_tag_name_width = max(max_tag_name_width,
font.getsize("Not Tagged")[0])
font.getbbox("Not Tagged")[2])

tag_sub_panes = []

Expand Down Expand Up @@ -435,7 +435,7 @@ def make_tagset_canvas(tag_string, tagset_pix_ids, show_subset_labels):
p_y += pane.size[1]
if tag_text is not None:
draw = ImageDraw.Draw(tag_canvas)
tt_w, tt_h = font.getsize(tag_text)
tt_w, tt_h = font.getbbox(tag_text)[2:]
h_offset = (total_height - tt_h)/2
draw.text((spacing, h_offset), tag_text, font=font,
fill=(50, 50, 50))
Expand Down

0 comments on commit ab5df60

Please sign in to comment.