Commit 564408cc authored by 任建锋's avatar 任建锋

Merge branch 'dev' of http://gitlab2.dui88.com/laoqifeng/zeroing-libs into dev

parents 0e85c3c0 35cac742
This diff is collapsed.
......@@ -6,7 +6,7 @@
"success"
],
"id": "pick-image",
"script": "var input = document.createElement('input');\ninput.type = 'file';\ninput.onchange = function (e) {\n processImage(input.files[0], function (imgData) {\n next('success', imgData);\n });\n};\ninput.click();\nfunction processImage(file, callback) {\n var reader = new FileReader();\n reader.readAsDataURL(file);\n reader.onload = function (e) {\n callback(reader.result);\n };\n}\n",
"script": "pick(function (imgData) {\n next('success', imgData);\n});\nfunction getExif(img, callback) {\n EXIF.getData(img, function () {\n var allMetaData = EXIF.getAllTags(this);\n callback(allMetaData);\n });\n}\nfunction pick(callback) {\n var fileInput = document.createElement(\"input\");\n fileInput.type = \"file\";\n fileInput.accept = \"image/*\";\n fileInput.style.display = \"none\";\n document.body.insertBefore(fileInput, document.body.firstChild);\n fileInput.addEventListener(\"change\", function (evt) {\n var mime = { \"png\": \"image/png\", \"jpg\": \"image/jpeg\", \"jpeg\": \"image/jpeg\", \"bmp\": \"image/bmp\" };\n var file = evt.target.files[0];\n var type = file.type;\n if (!type) {\n type = mime[file.name.match(/\\.([^\\.]+)$/i)[1]];\n }\n var fileReader = new FileReader();\n fileReader.onload = function () {\n getExif(file, function (exif) {\n var orientation = -1;\n if (exif) {\n orientation = exif[\"Orientation\"];\n }\n var image = new Image();\n image.onload = function () {\n var canvas = document.createElement(\"canvas\");\n var ctx = canvas.getContext(\"2d\");\n canvas.width = image.width;\n canvas.height = image.height;\n if (orientation > 4) {\n canvas.width = image.height;\n canvas.height = image.width;\n }\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n switch (orientation) {\n case 2:\n ctx.translate(canvas.width, 0);\n ctx.scale(-1, 1);\n break;\n case 3:\n ctx.translate(canvas.width, canvas.height);\n ctx.rotate(Math.PI);\n break;\n case 4:\n ctx.translate(0, canvas.height);\n ctx.scale(1, -1);\n break;\n case 5:\n ctx.rotate(0.5 * Math.PI);\n ctx.scale(1, -1);\n break;\n case 6:\n ctx.rotate(0.5 * Math.PI);\n ctx.translate(0, -image.height);\n break;\n case 7:\n ctx.rotate(0.5 * Math.PI);\n ctx.translate(canvas.width, -canvas.height);\n ctx.scale(-1, 1);\n break;\n case 8:\n ctx.rotate(-0.5 * Math.PI);\n ctx.translate(-canvas.height, 0);\n break;\n default:\n ctx.transform(1, 0, 0, 1, 0, 0);\n }\n ctx.drawImage(image, 0, 0);\n var imagetype = \"png\";\n if (orientation !== -1) {\n imagetype = \"jpeg\";\n }\n var resultURL = \"\";\n if (imagetype === \"jpg\" || imagetype === \"jpeg\") {\n resultURL = canvas.toDataURL(\"image/\" + imagetype);\n }\n else {\n resultURL = canvas.toDataURL(\"image/\" + imagetype);\n }\n callback(resultURL);\n image.parentNode.removeChild(image);\n fileInput.parentNode.removeChild(fileInput);\n };\n image.src = fileReader.result;\n image.style.display = \"none\";\n document.body.appendChild(image);\n fileInput.value = \"\";\n });\n };\n fileReader.readAsDataURL(file);\n }, false);\n fileInput.click();\n}\n",
"group": "other",
"type": "builtin"
}
......@@ -38,7 +38,7 @@
"success"
],
"id": "resize-image",
"script": "var width = engine.findVariable('width', args, props);\nvar height = engine.findVariable('height', args, props);\nvar cutType = engine.findVariable('cutType', args, props);\nvar type = engine.findVariable('type', args, props);\nvar quality = engine.findVariable('quality', args, props);\nvar img = args;\nif (typeof args === 'string') {\n img = new Image();\n img.onload = function () {\n deal();\n };\n img.onerror = function (e) {\n console.log(e);\n };\n img.src = args;\n}\nelse {\n deal();\n}\nfunction getExif(callback) {\n EXIF.getData(img, function () {\n var allMetaData = EXIF.getAllTags(this);\n callback(allMetaData);\n });\n}\nfunction deal() {\n getExif(function (allMetaData) {\n var m = cutType === 'inner' ? Math.min : Math.max;\n var r = m(width / img.width, height / img.height);\n var imgWidth = img.width * r;\n var imgHeight = img.height * r;\n var x = (width - imgWidth) / 2;\n var y = (height - imgHeight) / 2;\n var canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n var ctx = canvas.getContext('2d');\n ctx.translate(x, y);\n ctx.scale(r, r);\n allMetaData.Orientation = 1;\n if (allMetaData.Orientation) {\n var orientation = allMetaData.Orientation;\n switch (orientation) {\n case 2:\n ctx.translate(img.width, 0);\n ctx.scale(-1, 1);\n break;\n case 3:\n ctx.translate(img.width, img.height);\n ctx.rotate(Math.PI);\n break;\n case 4:\n ctx.translate(0, img.height);\n ctx.scale(1, -1);\n break;\n case 5:\n ctx.rotate(-0.5 * Math.PI);\n ctx.scale(-1, 1);\n ctx.translate(x / r - y / r, y / r - x / r);\n break;\n case 6:\n ctx.rotate(-0.5 * Math.PI);\n ctx.translate(-img.width + y / r - x / r, y / r - x / r);\n break;\n case 7:\n ctx.rotate(0.5 * Math.PI);\n ctx.scale(-1, 1);\n ctx.translate(-img.width + y / r - x / r, -img.height + x / r - y / r);\n break;\n case 8:\n ctx.rotate(-0.5 * Math.PI);\n ctx.translate(-img.width + y / r - x / r, -x / r + y / r);\n break;\n }\n }\n ctx.drawImage(img, 0, 0);\n var dataUrl = canvas.toDataURL('image/' + type, quality);\n next('success', dataUrl);\n });\n}\n",
"script": "var width = engine.findVariable('width', args, props);\nvar height = engine.findVariable('height', args, props);\nvar cutType = engine.findVariable('cutType', args, props);\nvar type = engine.findVariable('type', args, props);\nvar quality = engine.findVariable('quality', args, props);\nvar img = args;\nif (typeof args === 'string') {\n img = new Image();\n img.onload = function () {\n deal();\n };\n img.onerror = function (e) {\n console.log(e);\n };\n img.src = args;\n}\nelse {\n deal();\n}\nfunction deal() {\n var m = cutType === 'inner' ? Math.min : Math.max;\n var r = m(width / img.width, height / img.height);\n var imgWidth = img.width * r;\n var imgHeight = img.height * r;\n var x = (width - imgWidth) / 2;\n var y = (height - imgHeight) / 2;\n var canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n var ctx = canvas.getContext('2d');\n ctx.translate(x, y);\n ctx.scale(r, r);\n ctx.drawImage(img, 0, 0);\n var dataUrl = canvas.toDataURL('image/' + type, quality);\n next('success', dataUrl);\n}\n",
"group": "other",
"type": "builtin"
}
......@@ -6,13 +6,42 @@
},
"text": {
"type": "string",
"alias": "内容"
"alias": "文本内容"
},
"labelAlign": {
"alias": "文本对齐",
"type": "enum",
"enum": [
{
"label": "左对齐",
"value": "left"
},
{
"label": "居中对齐",
"value": "center"
},
{
"label": "右对齐",
"value": "right"
}
],
"default": "center"
},
"labSize": {
"alias": "文本大小",
"type": "number",
"default": 30
},
"padding": {
"type": "number",
"default": 10,
"alias": "边距"
},
"bgAlpha": {
"type": "number",
"default": 0.7,
"alias": "背景透明度"
},
"paddingH": {
"type": "number",
"alias": "横向边距"
......
......@@ -13,11 +13,8 @@
engine.injectProp(props, p);
}
function getTexture(uuid) {
return engine.Texture.from(uuid);
}
function getTextureByName(name) {
return getTexture(getAssetByName(name).uuid);
return engine.Texture.from(getAssetByName(name).uuid);
}
function getBlockAsset(type) {
return engine.getAssetByName(props.blockAssets[type]);
......@@ -853,7 +850,6 @@
};
return GameView;
}(engine.Container));
//# sourceMappingURL=GameView.js.map
var JumpHigh = (function (_super) {
tslib.__extends(JumpHigh, _super);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -8,7 +8,7 @@ export function getTexture(uuid) {
}
export function getTextureByName(name) {
return getTexture(getAssetByName(name).uuid);
return engine.Texture.from(getAssetByName(name).uuid);
}
export function getBlockAsset(type) {
......
......@@ -2,19 +2,106 @@
* Created by rockyl on 2019-11-16.
*/
let input = document.createElement('input');
input.type = 'file';
input.onchange = function (e) {
processImage(input.files[0], (imgData)=>{
next('success', imgData);
})
};
input.click();
pick(function (imgData) {
next('success', imgData);
});
function processImage(file, callback) {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e) {
callback(reader.result)
}
function getExif(img, callback) {
EXIF.getData(img, function () {
let allMetaData = EXIF.getAllTags(this);
callback(allMetaData)
});
}
function pick(callback) {
let fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "image/*";
fileInput.style.display = "none";
document.body.insertBefore(fileInput, document.body.firstChild);
fileInput.addEventListener("change", function (evt) {
let mime = {"png": "image/png", "jpg": "image/jpeg", "jpeg": "image/jpeg", "bmp": "image/bmp"};
let file = evt.target.files[0];
let type = file.type;
if (!type) {
type = mime[file.name.match(/\.([^\.]+)$/i)[1]];
}
let fileReader = new FileReader();
fileReader.onload = function () {
getExif(file, (exif) => {
//let exif = EXIF.readFromBinaryFile(arrayBuffer);
let orientation = -1;
if (exif) {
orientation = exif["Orientation"];
}
let image = new Image();
image.onload = function () {
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
canvas.width = image.width;
canvas.height = image.height;
if (orientation > 4) {
canvas.width = image.height;
canvas.height = image.width;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
switch (orientation) {
case 2:
// horizontal flip
ctx.translate(canvas.width, 0);
ctx.scale(-1, 1);
break;
case 3:
// 180° rotate left
ctx.translate(canvas.width, canvas.height);
ctx.rotate(Math.PI);
break;
case 4:
ctx.translate(0, canvas.height);
ctx.scale(1, -1);
break;
case 5:
ctx.rotate(0.5 * Math.PI);
ctx.scale(1, -1);
break;
case 6:
ctx.rotate(0.5 * Math.PI);
ctx.translate(0, -image.height);
break;
case 7:
ctx.rotate(0.5 * Math.PI);
ctx.translate(canvas.width, -canvas.height);
ctx.scale(-1, 1);
break;
case 8:
ctx.rotate(-0.5 * Math.PI);
ctx.translate(-canvas.height, 0);
break;
default:
ctx.transform(1, 0, 0, 1, 0, 0);
}
ctx.drawImage(image, 0, 0);
let imagetype = "png";
if (orientation !== -1) {
imagetype = "jpeg";
}
let resultURL = "";
if (imagetype === "jpg" || imagetype === "jpeg") {
resultURL = canvas.toDataURL("image/" + imagetype);
} else {
resultURL = canvas.toDataURL("image/" + imagetype);
}
callback(resultURL);
image.parentNode.removeChild(image);
fileInput.parentNode.removeChild(fileInput);
};
image.src = fileReader.result;
image.style.display = "none";
document.body.appendChild(image);
fileInput.value = "";
});
};
fileReader.readAsDataURL(file);
}, false);
fileInput.click();
}
......@@ -7,7 +7,6 @@ const height = engine.findVariable('height', args, props);
const cutType = engine.findVariable('cutType', args, props);
const type = engine.findVariable('type', args, props);
const quality = engine.findVariable('quality', args, props);
let img = args;
if (typeof args === 'string') {
img = new Image();
......@@ -18,79 +17,25 @@ if (typeof args === 'string') {
console.log(e);
};
img.src = args;
} else {
deal();
}
function getExif(callback) {
EXIF.getData(img, function () {
var allMetaData = EXIF.getAllTags(this);
callback(allMetaData)
});
else {
deal();
}
function deal() {
getExif((allMetaData) => {
let m = cutType === 'inner' ? Math.min : Math.max;
let r = m(width / img.width, height / img.height);
let imgWidth = img.width * r;
let imgHeight = img.height * r;
let x = (width - imgWidth) / 2;
let y = (height - imgHeight) / 2;
let canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext('2d');
//ctx.strokeStyle = 'blue';
//ctx.strokeRect(0, 0, width, height);
ctx.translate(x, y);
ctx.scale(r, r);
allMetaData.Orientation = 1;
if (allMetaData.Orientation) {
let orientation = allMetaData.Orientation;
switch (orientation) {
case 2: //水平翻转
ctx.translate(img.width, 0);
ctx.scale(-1, 1);
break;
case 3: //180°
ctx.translate(img.width, img.height);
ctx.rotate(Math.PI);
break;
case 4: //垂直翻转
ctx.translate(0, img.height);
ctx.scale(1, -1);
break;
case 5: //逆时针90°+水平翻转
ctx.rotate(-0.5 * Math.PI);
ctx.scale(-1, 1);
ctx.translate(x / r -y / r, y / r - x / r);
break;
case 6: //逆时针90°
ctx.rotate(-0.5 * Math.PI);
ctx.translate(-img.width + y / r - x / r, y / r - x / r);
break;
case 7: //顺时针90°+垂直翻转
ctx.rotate(0.5 * Math.PI);
ctx.scale(-1, 1);
ctx.translate(-img.width + y / r - x / r, -img.height + x / r - y / r);
break;
case 8: //顺时针90°
ctx.rotate(-0.5 * Math.PI);
ctx.translate(-img.width + y / r - x / r, -x / r + y / r);
break;
}
}
ctx.drawImage(img, 0, 0);
let dataUrl = canvas.toDataURL('image/' + type, quality);
next('success', dataUrl);
})
let m = cutType === 'inner' ? Math.min : Math.max;
let r = m(width / img.width, height / img.height);
let imgWidth = img.width * r;
let imgHeight = img.height * r;
let x = (width - imgWidth) / 2;
let y = (height - imgHeight) / 2;
let canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext('2d');
ctx.translate(x, y);
ctx.scale(r, r);
ctx.drawImage(img, 0, 0);
let dataUrl = canvas.toDataURL('image/' + type, quality);
next('success', dataUrl);
}
......@@ -6,13 +6,33 @@
},
"text": {
"type": "string",
"alias": "内容"
"alias": "文本内容"
},
"labelAlign": {
"alias": "文本对齐",
"type": "enum",
"enum": [
{"label":"左对齐", "value":"left"},
{"label":"居中对齐", "value":"center"},
{"label":"右对齐", "value":"right"}
],
"default": "center"
},
"labSize": {
"alias": "文本大小",
"type": "number",
"default": 30
},
"padding": {
"type": "number",
"default": 10,
"alias": "边距"
},
"bgAlpha": {
"type": "number",
"default": 0.7,
"alias": "背景透明度"
},
"paddingH": {
"type": "number",
"alias": "横向边距"
......@@ -46,4 +66,4 @@
"output": [
"success"
]
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment