Skip to content

Commit

Permalink
Fix checking URL for base64 images
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuprynowicz committed Dec 21, 2024
1 parent b85935c commit d71264f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libraries/entities/src/EntityItemPropertiesDocs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,9 @@
*
* @typedef {object} Entities.EntityProperties-Image
* @property {Vec3} dimensions=0.1,0.1,0.01 - The dimensions of the entity.
* @property {string} imageURL="" - The URL of the image to use.
* @property {string} imageURL="" - The URL of the image to use. It can also contain a base64 encoded image, in the same format as glTF.
* For network transmitted entities there's about 1000-character limit for the length of this field. For base64 image
* the property string needs to begin with `data:image/png;base64,`, `data:image/jpeg;base64,` or `data:image/webp;base64,`.
* @property {boolean} emissive=false - <code>true</code> if the image should be emissive (unlit), <code>false</code> if it
* shouldn't.
* @property {boolean} keepAspectRatio=true - <code>true</code> if the image should maintain its aspect ratio,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs
}

QString urlString = url.toString();
if (content.isEmpty() && (urlString.contains("data:image/jpeg;base64,")
|| urlString.contains("data:image/png;base64,")
|| urlString.contains("data:image/webp;base64,"))) {
if (content.isEmpty() && (urlString.startsWith("data:image/jpeg;base64,")
|| urlString.startsWith("data:image/png;base64,")
|| urlString.startsWith("data:image/webp;base64,"))) {
QString binaryUrl = urlString.split(",")[1];
auto decodedContent = binaryUrl.isEmpty() ? QByteArray() : QByteArray::fromBase64(binaryUrl.toUtf8());
if (!decodedContent.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/model-serializers/src/GLTFSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ HFMTexture GLTFSerializer::getHFMTexture(const cgltf_texture *texture) {
hfmTex.filename = textureUrl.toEncoded().append(QString::number(imageIndex).toUtf8());
}

if (url.contains("data:image/jpeg;base64,") || url.contains("data:image/png;base64,") || url.contains("data:image/webp;base64,")) {
if (url.startsWith("data:image/jpeg;base64,") || url.startsWith("data:image/png;base64,") || url.startsWith("data:image/webp;base64,")) {
hfmTex.content = requestEmbeddedData(url);
}
}
Expand Down

0 comments on commit d71264f

Please sign in to comment.