Skip to content

Commit

Permalink
Merge pull request #1095 from mluessi/fix_doc_limit_fig_width
Browse files Browse the repository at this point in the history
FIX: doc image width < 850
  • Loading branch information
agramfort committed Jan 23, 2014
2 parents e47a343 + d9974a8 commit 1011931
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/sphinxext/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,27 @@ def make_thumbnail(in_fname, out_fname, width, height):
thumb.save(out_fname)


def scale_image(in_fname, max_width):
"""Scale image such that width <= max_width
"""
img = Image.open(in_fname)
width_in, height_in = img.size

if width_in <= max_width:
return

scale = max_width / float(width_in)

width_sc = int(round(scale * width_in))
height_sc = int(round(scale * height_in))

# resize the image
img.thumbnail((width_sc, height_sc), Image.ANTIALIAS)

# overwrite the image
img.save(in_fname)


def get_short_module_name(module_name, obj_name):
""" Get the shortest possible module name """
parts = module_name.split('.')
Expand Down Expand Up @@ -764,13 +785,18 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery):
plt.savefig(image_path % fig_num, facecolor='black')
else:
plt.savefig(image_path % fig_num)

# make sure the image is not too large
scale_image(image_path % fig_num, 850)
figure_list.append(image_fname % fig_num)
last_fig_num = fig_num

e = mlab.get_engine()
for scene in e.scenes:
last_fig_num += 1
mlab.savefig(image_path % last_fig_num)
# make sure the image is not too large
scale_image(image_path % last_fig_num, 850)
figure_list.append(image_fname % last_fig_num)
mlab.close(scene)

Expand Down

0 comments on commit 1011931

Please sign in to comment.