Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

introduce createDummyImage

  • Loading branch information...
commit 5e8660923da3807a9970addebbc9cb845e799aa8 1 parent 01b29b8
@myakura authored
Showing with 16 additions and 12 deletions.
  1. +4 −9 dummysan.html
  2. +12 −3 dummysan.js
View
13 dummysan.html
@@ -23,21 +23,16 @@
button.addEventListener('click', function () {
// 入力された値を数値として取得
- var parsedInput = Dummysan.parse(input.value);
+ var parsedInput = Dummysan.parseInput(input.value);
if (!parsedInput.length) return;
var dummyWidth = parsedInput[0],
dummyHeight = parsedInput[1];
- // ダミー画像を描画したcanvas要素を取得
- var canvas = Dummysan.create(dummyWidth, dummyHeight);
+ // ダミー画像を取得
+ var img = Dummysan.createDummyImage(dummyWidth, dummyHeight);
- // 取得したダミー画像をimg要素に格納して追加
- if (!!canvas) {
- var img = document.createElement('img');
- img.src = canvas.toDataURL();
- rack.appendChild(img);
- }
+ rack.appendChild(img);
}, false);
</script>
View
15 dummysan.js
@@ -19,7 +19,7 @@ function isNum(suspect) {
return typeof suspect === 'number' && isFinite(suspect);
};
-Dummysan.parse = function (string) {
+Dummysan.parseInput = function (string) {
// "320 200", "120,200", "240x80" などにマッチ
var re = /^(?:\u0020*)(\d+)(?:\u0020*[\u0020,x]\u0020*)(\d+)(?:\u0020*)$/;
var result = [],
@@ -35,7 +35,7 @@ Dummysan.parse = function (string) {
return result;
};
-Dummysan.create = function (width, height) {
+Dummysan.createDummyCanvas = function (width, height) {
if (!(isNum(width) && isNum(height))) return;
canvas.width = width;
@@ -74,7 +74,16 @@ Dummysan.create = function (width, height) {
// テキストを描画する
ctx.fillText(width + '×' + height, hw, hh);
- return canvas; // 今はとりあえずcanvasを返しとく
+ return canvas;
};
+
+Dummysan.createDummyImage = function (width, height) {
+ var res = document.createElement('img');
+ var cvs = Dummysan.createDummyCanvas(width, height);
+ res.src = cvs.toDataURL();
+ return res;
+}
+
+
}(this, this.document));
Please sign in to comment.
Something went wrong with that request. Please try again.