[FIX] web_editor: image size

Make sure to create an image of a size larger than zero. A size of zero
will generate a traceback.
This commit is contained in:
Nicolas Martinelli
2016-03-03 13:24:40 +01:00
parent db95dcd8bc
commit fad4788272
2 changed files with 3 additions and 1 deletions
+2
View File
@@ -84,6 +84,8 @@ class Web_Editor(http.Controller):
:returns PNG image converted from given font
"""
# Make sure we have at least size=1
size = max(1, size)
# Initialize font
addons_path = http.addons_manifest['web']['addons_path']
font_obj = ImageFont.truetype(addons_path + font, size)
@@ -133,7 +133,7 @@ var font_to_img = function ($editable) {
});
if (content) {
var color = $font.css("color").replace(/\s/g, '');
var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+$font.height(), window.encodeURI(content), window.encodeURI(color));
var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+Math.max(1, $font.height()), window.encodeURI(content), window.encodeURI(color));
var $img = $("<img/>").attr("src", src)
.attr("data-class", $font.attr("class"))
.attr("class", $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), '')) // remove inline font-awsome style