Skip to content

Commit 65343fb

Browse files
committed
Add check for blank images #3975
1 parent a252d71 commit 65343fb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/messageicons/icons/generate.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,29 @@ icons.forEach(icon => {
4040
png.decode(function (pixels) {
4141
var rgba = new Uint8Array(pixels);
4242
var isTransparent = false;
43-
for (var i=0;i<rgba.length;i+=4)
43+
for (var i=0;i<rgba.length;i+=4) {
4444
if (rgba[i+3]<255) isTransparent=true;
45+
}
4546
if (!isTransparent) { // make it transparent
4647
for (var i=0;i<rgba.length;i+=4)
4748
rgba[i+3] = 255-rgba[i];
4849
}
50+
var allSet = true, allUnset = true;
51+
for (var i=0;i<rgba.length;i+=4) {
52+
rgba[i+0] = 0; // ensure all pixels are black (data is in transparency)
53+
rgba[i+1] = 0;
54+
rgba[i+2] = 0;
55+
if (rgba[i+3]>0) allUnset=false;
56+
if (rgba[i+3]<255) allSet=false;
57+
}
4958

5059
imgOptions.width = png.width;
5160
imgOptions.height = png.height;
5261
var img = imageconverter.RGBAtoString(rgba, imgOptions);
5362
iconImages[index] = img;
5463
console.log("Loaded "+icon.icon);
55-
if (img.length != IMAGE_BYTES) throw new Error("Image size should be 76 bytes");
64+
if (allSet || allUnset) throw new Error(icon.icon+" Image is blank! (is it saved as 8 bit RGB PNG?)");
65+
if (img.length != IMAGE_BYTES) throw new Error(icon.icon+" Image size should be 76 bytes");
5666
r(); // done
5767
});
5868
}));

0 commit comments

Comments
 (0)