Skip to content
Snippets Groups Projects
Unverified Commit b12d8248 authored by Bryce Taylor's avatar Bryce Taylor Committed by GitHub
Browse files

Merge pull request #5974 from apple502j/zero-zero-backpack

Fix backpacking zero-height/width costumes
parents 5ea74c6a 18451a59
No related branches found
No related tags found
1 merge request!1Synching Fork
...@@ -6,17 +6,24 @@ const jpegThumbnail = dataUrl => new Promise((resolve, reject) => { ...@@ -6,17 +6,24 @@ const jpegThumbnail = dataUrl => new Promise((resolve, reject) => {
const maxDimension = 96; // 3x the maximum displayed size of 32px const maxDimension = 96; // 3x the maximum displayed size of 32px
if (image.height > image.width) { if (image.height < 1 || image.width < 1) {
canvas.height = maxDimension; canvas.width = canvas.height = maxDimension;
canvas.width = (maxDimension / image.height) * image.width; // drawImage can fail if image height/width is less than 1
// Use blank image; the costume is too small to render anyway
ctx.fillStyle = 'white'; // Create white background, since jpeg doesn't have transparency
ctx.fillRect(0, 0, canvas.width, canvas.height);
} else { } else {
canvas.width = maxDimension; if (image.height > image.width) {
canvas.height = (maxDimension / image.width) * image.height; canvas.height = maxDimension;
canvas.width = (maxDimension / image.height) * image.width;
} else {
canvas.width = maxDimension;
canvas.height = (maxDimension / image.width) * image.height;
}
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
} }
ctx.fillStyle = 'white'; // Create white background, since jpeg doesn't have transparency
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
resolve(canvas.toDataURL('image/jpeg', 0.92 /* quality */)); // Default quality is 0.92 resolve(canvas.toDataURL('image/jpeg', 0.92 /* quality */)); // Default quality is 0.92
}; };
image.onerror = err => { image.onerror = err => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment