Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCC-218 fixed svg to png conversion error when height or width attribute were missing #150

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Scratch2Catrobat Converter
short_name: S2CC
version: 0.10.0
build_name: Aegean cat
build_number: 998
build_number: 1005
build_type: S2CC

;-------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/scratchtocatrobat/tools/svgtopng.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ def _parse_and_rewrite_svg_file(svg_input_path, svg_output_path):
if 'width' in root.attrib and float((root.attrib['width']).strip('px%')) <= 0:
root.attrib['width'] = '1'

#some SVGs do not contain height and width attributes - viewbox attribute can be used to determine those parameters
if not 'height' in root.attrib or not 'width' in root.attrib:
if 'viewBox' in root.attrib:
viewBox_values = _get_viewbox_values(root.attrib['viewBox'])
height = viewBox_values[3]
width = viewBox_values[2]
root.set('height', str(height))
root.set('width', str(width))

# uncrop image if and only if everything is in a g tag
for child in root:
Expand Down