Skip to content
This repository was archived by the owner on Mar 28, 2026. It is now read-only.

Commit ccfe4de

Browse files
Allows filenames to be used to specify element style icons (this is really for themes, where the images can be loaded relative to the theme definition).
1 parent c516d45 commit ccfe4de

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

structurizr-core/src/com/structurizr/util/ImageUtils.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,30 @@ public static String getImageAsDataUri(File file) throws IOException {
6969
return "data:" + contentType + ";base64," + base64Content;
7070
}
7171

72-
public static void validateImage(String url) {
73-
if (StringUtils.isNullOrEmpty(url)) {
72+
public static void validateImage(String imageDescriptor) {
73+
if (StringUtils.isNullOrEmpty(imageDescriptor)) {
7474
return;
7575
}
7676

77-
url = url.trim();
77+
imageDescriptor = imageDescriptor.trim();
7878

79-
if (Url.isUrl(url)) {
79+
if (Url.isUrl(imageDescriptor)) {
8080
// all good
8181
return;
8282
}
8383

84-
if (url.startsWith("data:image")) {
85-
if (ImageUtils.isSupportedDataUri(url)) {
86-
// all good
84+
if (imageDescriptor.toLowerCase().endsWith(".png") || imageDescriptor.toLowerCase().endsWith(".jpg") || imageDescriptor.toLowerCase().endsWith(".jpeg") || imageDescriptor.toLowerCase().endsWith(".gif")) {
85+
// it's just a filename
86+
return;
87+
}
88+
89+
if (imageDescriptor.startsWith("data:image")) {
90+
if (ImageUtils.isSupportedDataUri(imageDescriptor)) {
91+
// it's a PNG/JPG data URI
8792
return;
8893
} else {
8994
// it's a data URI, but not supported
90-
throw new IllegalArgumentException("Only PNG and JPG data URIs are supported: " + url);
95+
throw new IllegalArgumentException("Only PNG and JPG data URIs are supported: " + imageDescriptor);
9196
}
9297
}
9398

structurizr-core/test/unit/com/structurizr/util/ImageUtilsTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ void validateImage() {
159159
ImageUtils.validateImage("https://structurizr.com/image.png");
160160
ImageUtils.validateImage("data:image/png;base64,iVBORw0KGg");
161161
ImageUtils.validateImage("data:image/jpeg;base64,iVBORw0KGg");
162+
ImageUtils.validateImage("image.png");
163+
ImageUtils.validateImage("image.jpg");
164+
ImageUtils.validateImage("image.jpeg");
165+
ImageUtils.validateImage("image.gif");
162166

163167
//disallowed
164168
try {

0 commit comments

Comments
 (0)