mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
check for transparency in hat transparency-bounding-box for avatars, fixes #117
This commit is contained in:
parent
f920811405
commit
f2dda3b939
28
lib/skins.js
28
lib/skins.js
@ -43,7 +43,29 @@ exp.extract_helm = function(rid, facefile, buffer, outname, callback) {
|
|||||||
if (buf_err) {
|
if (buf_err) {
|
||||||
callback(buf_err);
|
callback(buf_err);
|
||||||
} else {
|
} else {
|
||||||
skin_img.crop(40, 8, 47, 15, function(crop_err, helm_img) {
|
// crop to hat transparency-bounding-box
|
||||||
|
skin_img.crop(32, 0, 63, 31, function(area_err, helm_area) {
|
||||||
|
if (area_err) {
|
||||||
|
callback(area_err);
|
||||||
|
} else {
|
||||||
|
/* eslint-disable no-labels */
|
||||||
|
var is_opaque = true;
|
||||||
|
if (skin_img.__trans) { // eslint-disable-line no-underscore-dangle
|
||||||
|
xloop:
|
||||||
|
for (var x = 0; x < helm_area.width(); x++) {
|
||||||
|
for (var y = 0; y < helm_area.height(); y++) {
|
||||||
|
// check if transparency-bounding-box has transparency
|
||||||
|
if (helm_area.getPixel(x, y).a !== 100) {
|
||||||
|
is_opaque = false;
|
||||||
|
break xloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* eslint-enable no-labels */
|
||||||
|
} else {
|
||||||
|
is_opaque = true;
|
||||||
|
}
|
||||||
|
skin_img.crop(8, 8, 15, 15, function(crop_err, helm_img) {
|
||||||
if (crop_err) {
|
if (crop_err) {
|
||||||
callback(crop_err);
|
callback(crop_err);
|
||||||
} else {
|
} else {
|
||||||
@ -51,7 +73,7 @@ exp.extract_helm = function(rid, facefile, buffer, outname, callback) {
|
|||||||
if (img_err) {
|
if (img_err) {
|
||||||
callback(img_err);
|
callback(img_err);
|
||||||
} else {
|
} else {
|
||||||
if (!skin_img.__trans) {
|
if (is_opaque) {
|
||||||
logging.debug(rid, "Skin is not transparent, skipping helm!");
|
logging.debug(rid, "Skin is not transparent, skipping helm!");
|
||||||
callback(null);
|
callback(null);
|
||||||
} else {
|
} else {
|
||||||
@ -80,6 +102,8 @@ exp.extract_helm = function(rid, facefile, buffer, outname, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// resizes the image file +inname+ to +size+ by +size+ pixels
|
// resizes the image file +inname+ to +size+ by +size+ pixels
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user