Skip to content

Commit

Permalink
#25247 Fixing case when we try to get dimensions from a broken svg (#…
Browse files Browse the repository at this point in the history
…25802)

* #25247 Fixing case when we try to get dimensions from a broken svg

* #25247 Fixing case when we try to get dimensions from a broken svg

---------

Co-authored-by: nollymar <[email protected]>
  • Loading branch information
nollymar and nollymar authored Aug 17, 2023
1 parent f6b4e1e commit ec6a839
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public void test_dimensions() {
assert (dim.getHeight() == 772d);
assert (dim.getWidth() == 1024d);

url = getClass().getResource("/images/test.svg");
incomingFile = new File(url.getFile());

dim = imageApi.getWidthHeight(incomingFile);
assert (dim.getHeight() > 0);
assert (dim.getWidth() > 0);

//We should get dimensions even when the svg file is actually a png
url = getClass().getResource("/images/png_as_svg.svg");
incomingFile = new File(url.getFile());

dim = imageApi.getWidthHeight(incomingFile);
assert (dim.getHeight() > 0);
assert (dim.getWidth() > 0);

}


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ public Dimension getWidthHeight(final File imageFile) {
}

if (imageFile.getName().toLowerCase().endsWith(".svg")) {
return getWidthHeightofSVG(imageFile);
try {
return getWidthHeightofSVG(imageFile);
} catch (Exception e){
//If invoking the getWidthHeightofSVG method fails, we will try to get dimensions using the inputStream
Logger.debug(this, "Error getting dimensions of SVG file: " + imageFile.getName(), e);
}
}


Expand Down

0 comments on commit ec6a839

Please sign in to comment.