LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Tuesday, May 7, 2019

imgの元画像の幅(width)と高さ(height)を取得したい


naturalWidth と naturalHeight で取得できました
  • document.getElementById("image_id").naturalWidth;
  • document.getElementById("image_id").element.naturalHeight;



コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
<body>
<button id="bt">button</button>
<br>
<img id="source" src="画像URL">

<script>

document.getElementById('bt').onclick = getOriginalSize;

function getOriginalSize() {
  var source = document.getElementById('source');
  var originalWidth = source.naturalWidth;
  var originalHeight = source.naturalHeight;
  alert([originalWidth, originalHeight]);
}

</script>

</body>
</html>


Latest post

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...