{"id":3578,"date":"2019-04-23T16:48:10","date_gmt":"2019-04-23T07:48:10","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=3578"},"modified":"2019-04-24T18:55:34","modified_gmt":"2019-04-24T09:55:34","slug":"%e5%a4%a7%e3%81%8d%e3%81%aa%e7%94%bb%e5%83%8f%e3%82%92javascript%e3%81%a7%e3%83%aa%e3%82%b5%e3%82%a4%e3%82%ba%e3%81%97%e3%81%a6%e3%81%8b%e3%82%89ajax%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b%e6%96%b9","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=3578","title":{"rendered":"\u5927\u304d\u306a\u753b\u50cf\u3092JavaScript\u3067\u30ea\u30b5\u30a4\u30ba\u3057\u3066\u304b\u3089Ajax\u9001\u4fe1\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593 <a href=\"https:\/\/blog.capilano-fw.com\/?p=3386\">wordpress\u307f\u305f\u3044\u306a\u30c9\u30e9\u30c3\u30b0\u30fb\u30a2\u30f3\u30c9\u30fb\u30c9\u30ed\u30c3\u30d7\u3092Vue\u3067\u5b9f\u88c5<\/a>\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u8a18\u4e8b\u306e\u76ee\u7684\u306f\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u6a5f\u80fd\u306e\u5148\u3067\u306f\u753b\u50cf\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u6700\u8fd1\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3067\u306f\u753b\u50cf\u3092\u30b5\u30fc\u30d0\u30fc\u3078\u4fdd\u5b58\u3059\u308b\u3068\u3044\u3046\u306e\u306f\u73cd\u3057\u3044\u3053\u3068\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304c\u3001\u5b9f\u306f\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u5074\u306e\u72b6\u6cc1\u304c\u5909\u5316\u3057\u3066\u304d\u305f\u3053\u3068\u3067\u3042\u308b\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u304c\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u30b9\u30de\u30db\u30fb\u30ab\u30e1\u30e9\u306e\u9ad8\u89e3\u50cf\u5ea6\u5316\u306e\u305b\u3044\u3067\u753b\u50cf\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3046<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u30b5\u30a4\u30ba\u304c\u5927\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u306e\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u306d\u3002<\/p>\n<p>\u7279\u306b\u307e\u3060\u65e5\u672c\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u78ba\u8a8d\u30da\u30fc\u30b8\u3092\u631f\u3080\u5834\u5408\u3082\u591a\u304f\u5b58\u5728\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u305d\u306e\u5834\u5408\uff08\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u53b3\u5bc6\u306b\u3059\u308b\u306a\u3089\uff09\u753b\u50cf\u30b5\u30a4\u30ba\u304c\u5927\u304d\u3044\u5834\u5408\u306f\uff11\u756a\u3068\uff12\u756a\u3067\u753b\u50cf\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u5fc5\u8981\u304c\u3067\u3066\u304d\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u540d\u524d\u306a\u3069\u3092\u5165\u529b\u3059\u308b\u30da\u30fc\u30b8\u3000<strong>\uff08\u2190\u3053\u3053\u3067\u753b\u50cf\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\uff09<\/strong><\/li>\n<li>\u5165\u529b\u3057\u305f\u3082\u306e\u3092\u78ba\u8a8d\u3059\u308b\u30da\u30fc\u30b8\u3000<strong>\uff08\u2190\u3053\u3053\u3067\u3082\u753b\u50cf\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\uff09<\/strong><\/li>\n<li>\u5b8c\u4e86<\/li>\n<\/ol>\n<p>\u3053\u308c\u3067\u306f\u5f85\u3061\u6642\u9593\u304c\u9577\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3057\u3001\u30c7\u30fc\u30bf\u9001\u4fe1\u3059\u308b\u3054\u3068\u306b\u30b9\u30de\u30db\u306e\u901a\u4fe1\u901f\u5ea6\u5236\u9650\u3092\u6c17\u306b\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f<strong>\u9078\u629e\u3055\u308c\u305f\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u30d6\u30e9\u30a6\u30b6\u3067\u30b5\u30a4\u30ba\u5909\u66f4\u3057\u3066\u304b\u3089\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5<\/strong>\u3092Laravel + Vue\u3067\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u305f\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u266a<br \/>\n\uff08\u6700\u5f8c\u306b\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3581 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/3.png\" alt=\"\" width=\"260\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/3.png 260w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/3-244x300.png 244w\" sizes=\"auto, (max-width: 260px) 100vw, 260px\" \/><\/p>\n<p>\u958b\u767a\u74b0\u5883\uff1a Laravel 5.8\u3001Vue 2.6\uff08JavaScript\u306e\u8a18\u8ff0\u6cd5\u306fES6\uff09<\/p>\n<h1>HTML\u90e8\u5206\u3092\u3064\u304f\u308b<\/h1>\n<p>\u307e\u305a\u306f\u30d9\u30fc\u30b9\u3068\u306a\u308bHTML\u90e8\u5206\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u3068\u3044\u3063\u3066\u3082\u3001<code>Vue<\/code>\u3068<code>axios<\/code>\u3092<code>cdn<\/code>\u3067\u8aad\u307f\u8fbc\u307f\u3001\u305d\u308c\u305e\u308c\u30a4\u30d9\u30f3\u30c8\u304c\u3064\u3044\u305f\u300c\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u30dc\u30c3\u30af\u30b9\u300d\u3068\u300c\u9001\u4fe1\u30dc\u30bf\u30f3\u300d\u3092\u914d\u7f6e\u3057\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3582\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/l58-test-client_resize.png\" alt=\"\" width=\"259\" height=\"69\" \/><\/p>\n<p>\u203b \u306a\u304a\u3001\u8907\u6570\u9078\u629e\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001Vue\u306e\u5909\u6570\u306e\u4e2d\u8eab\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li><strong>maxWidth<\/strong>\u3000\u30fb\u30fb\u30fb\u3000\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u753b\u50cf\u306e\u6700\u5927\u5e45<\/li>\n<li><strong>smallImages<\/strong>\u3000\u30fb\u30fb\u30fb\u3000\u30ea\u30b5\u30a4\u30ba\u3055\u308c\u305f\u753b\u50cf\u306e\u914d\u5217<\/li>\n<\/ol>\n<p>\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\"&gt;\r\n    <strong>&lt;input type=\"file\" accept=\"image\/*\" multiple @change=\"onImageChange\"&gt;<\/strong>\r\n    &lt;br&gt;\r\n    <strong>&lt;button type=\"button\" @click=\"onSubmit\"&gt;\u9001\u4fe1&lt;\/button&gt;<\/strong>\r\n&lt;\/div&gt;\r\n<strong>&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/axios\/0.18.0\/axios.min.js\"&gt;&lt;\/script&gt;<\/strong>\r\n<strong>&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.10\/dist\/vue.min.js\"&gt;&lt;\/script&gt;<\/strong>\r\n&lt;script&gt;\r\n\r\n    new Vue({\r\n        el: '#app',\r\n        data: {\r\n            <strong>maxWidth: 300,<\/strong>\r\n<strong>            smallImages: []<\/strong>\r\n        },\r\n        methods: {\r\n            onSubmit() {\r\n\r\n                \/\/ \u3053\u3053\u3067Ajax\u9001\u4fe1\r\n\r\n            },\r\n            onImageChange() {\r\n\r\n                \/\/ \u3053\u3053\u3067\u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba\r\n\r\n            }\r\n        }\r\n    });\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h1>JavaScript\u90e8\u5206\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306fJavaScript\u90e8\u5206\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u5b9f\u88c5\u65b9\u6cd5\u306e\u624b\u9806<\/h2>\n<p>\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>HTML5\u306ecanvas\u8981\u7d20\u3092\u3064\u304f\u308b\uff08\u8868\u793a\u306f\u3057\u307e\u305b\u3093\uff09<\/li>\n<li>canvas\u306e\u30b5\u30a4\u30ba\u3092\u5909\u66f4<\/li>\n<li>\u9078\u629e\u753b\u50cf\u3092canvas\u306b\u63cf\u753b<\/li>\n<li>\u63cf\u753b\u3057\u305f\u753b\u50cf\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/li>\n<\/ol>\n<h2>\u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u90e8\u5206<\/h2>\n<p>\u3067\u306f\u3001\u4eca\u56de\u8a18\u4e8b\u306e\u30e1\u30a4\u30f3\u306b\u306a\u308bJavaScript\u3067\u9078\u629e\u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u90e8\u5206<code>onImageChange()<\/code>\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u304b\u3089\u3002<\/p>\n<pre><strong>onImageChange(e) {<\/strong>\r\n\r\n<strong>    this.smallImages = [];<\/strong>\r\n<strong>    const files = e.target.files;<\/strong>\r\n\r\n<strong>    for(let file of files) {<\/strong>\r\n\r\n<strong>        let reader = new FileReader();<\/strong>\r\n<strong>        reader.readAsDataURL(file);<\/strong>\r\n<strong>        reader.onload = (e) =&gt; {<\/strong>\r\n\r\n<strong>            let img = new Image();<\/strong>\r\n<strong>            img.onload = () =&gt; {<\/strong>\r\n\r\n<strong>                let width = img.width;<\/strong>\r\n<strong>                let height = img.height;<\/strong>\r\n\r\n<strong>                if(width &gt; this.maxWidth) {<\/strong>\r\n\r\n<strong>                    height = Math.round(height * this.maxWidth \/ width);<\/strong>\r\n<strong>                    width = this.maxWidth;<\/strong>\r\n\r\n<strong>                }<\/strong>\r\n\r\n<strong>                let canvas = document.createElement('canvas');<\/strong>\r\n<strong>                canvas.width = width;<\/strong>\r\n<strong>                canvas.height = height;<\/strong>\r\n<strong>                let ctx = canvas.getContext('2d');<\/strong>\r\n<strong>                ctx.drawImage(img, 0, 0, width, height);<\/strong>\r\n<strong>                ctx.canvas.toBlob((blob) =&gt; {<\/strong>\r\n\r\n<strong>                    const imageFile = new File([blob], file.name, {<\/strong>\r\n<strong>                        type: file.type,<\/strong>\r\n<strong>                        lastModified: Date.now()<\/strong>\r\n<strong>                    });<\/strong>\r\n<strong>                    this.smallImages.push(imageFile);<\/strong>\r\n\r\n<strong>                }, file.type, 1);<\/strong>\r\n\r\n<strong>            };<\/strong>\r\n<strong>            img.src = e.target.result;<\/strong>\r\n\r\n<strong>        };<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u5c11\u3057\u30b3\u30fc\u30c9\u304c\u8907\u96d1\u3067\u3059\u304c\u3072\u3068\u3064\u305a\u3064\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u753b\u50cf\u304c\u9078\u629e\u3055\u308c\u305f\u3089\u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u5168\u30d5\u30a1\u30a4\u30eb\u3092<code>FileReader<\/code>\u3092\u901a\u3057\u3066\u8aad\u307f\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u305d\u306e\u8aad\u307f\u51fa\u3057\u304c\u5b8c\u4e86\u3057\u305f\u3089<code>Image<\/code>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057<code>onload<\/code>\u306e\u4e2d\u3067\u3001\u305d\u306e\u753b\u50cf\u3068\u540c\u3058\u30b5\u30a4\u30ba\u306ecanvas\u306b\u63cf\u753b\u3057\u3066\u3044\u304f\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u6642\u3001\u3082\u3057\u753b\u50cf\u306e\u5e45\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u6700\u5927\u5024\uff08\u4e0a\u306e\u4f8b\u3067\u306f300px\uff09\u3088\u308a\u3082\u5927\u304d\u3051\u308c\u3070canvas\u306e\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3057\u3066\u304b\u3089\u753b\u50cf\u3092\u63cf\u753b\u3059\u308b\u3053\u3068\u3067\u30ea\u30b5\u30a4\u30ba\u3092\u5b9f\u73fe\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u753b\u50cf\u306e\u63cf\u753b\u304c\u5b8c\u4e86\u3057\u305f\u3089<code>toBlob()<\/code>\u3092\u4f7f\u3063\u3066\u3001<code>File<\/code>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057<code>smallImages<\/code>\u914d\u5217\u306b\u3072\u3068\u3064\u305a\u3064\u683c\u7d0d\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u3061\u306a\u307f\u306bIE 11\u3067\u306f<code>toBlob()<\/code>\u306f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001<a href=\"https:\/\/github.com\/blueimp\/JavaScript-Canvas-to-Blob\">JavaScript Canvas to Blob<\/a>\u3068\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u3010\u8ffd\u8a18\uff1a2019.4.24\u3011IE 11\u306e\u5834\u5408 <code>File API<\/code>\u3067\u3082\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u3092\u3054\u6307\u6458\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002\u3082\u3057IE 11\u3067\u5229\u7528\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u76f4\u63a5<code>blog<\/code>\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u305f\u3060\u3057\u3001ES6\u3067\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u30b3\u30fc\u30c9\u81ea\u4f53\u3092<code>babel<\/code>\u306a\u3069\u3067\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff09<\/p>\n<pre>ctx.canvas.toBlob((blob) =&gt; {\r\n\r\n    <strong>blob.lastModifiedDate = new Date();<\/strong>\r\n<strong>    blob.name = file.name;<\/strong>\r\n    this.smallImages.push(blob);\r\n\r\n    if(this.smallImages.length == files.length) {\r\n\r\n        this.isResizing = false;    \/\/ \u30ea\u30b5\u30a4\u30ba\u5b8c\u4e86\uff01\r\n\r\n    }\r\n\r\n}, file.type, 1);<\/pre>\n<p>\u306a\u304a\u3001\u30b3\u30fc\u30c9\u306e\u4e2d\u306b\u3067\u3066\u304f\u308b<code>file.name<\/code>\u306f\u30d5\u30a1\u30a4\u30eb\u540d\u3001<code>file.type<\/code>\u306f\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u306e<code>mime-type<\/code>\uff08<code>image\/png<\/code>\u306a\u3069\uff09\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30c7\u30fc\u30bf\u9001\u4fe1\u3059\u308b\u90e8\u5206<\/h2>\n<p>\u30ea\u30b5\u30a4\u30ba\u3055\u308c\u305f\u753b\u50cf\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u308c\u3070\u3001\u5f8c\u306fAjax\u3067\u9001\u4fe1\u3059\u308b\u3060\u3051\u3067\u3059\u3002<br \/>\n\u753b\u50cf\u30c7\u30fc\u30bf\u306f<code>FormData<\/code>\u3092\u4f7f\u3046\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre>methods: {\r\n    onSubmit() {\r\n\r\n        <strong>let formData = new FormData;<\/strong>\r\n\r\n<strong>        this.smallImages.forEach((smallImage) =&gt; {<\/strong>\r\n\r\n<strong>            formData.append('images[]', smallImage);<\/strong>\r\n\r\n<strong>        });<\/strong>\r\n\r\n        axios.post('\/resize_ajax', formData)\r\n            .then((response) =&gt; {\r\n\r\n                \/\/ Ajax\u901a\u4fe1\u304c\u6210\u529f\u3057\u305f\u6642\r\n\r\n            });\r\n\r\n    },\r\n\r\n    \/\/ \u7701\u7565<\/pre>\n<h2>\u6ce8\u610f\u3059\u3079\u304d\u70b9<\/h2>\n<p>\u5b9f\u306f\u4e0a\u306e\u30b3\u30fc\u30c9\u306b\u306f\u5165\u3063\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u6c17\u3092\u3064\u3051\u3066\u304a\u304f\u3079\u304d\u70b9\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u308c\u306f\u3001\u51e6\u7406\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001<code>FileReader()<\/code>\u3084<code>Image()<\/code>\u306f\u3001\u975e\u540c\u671f\u3067\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067<strong>\u300c\u307e\u3060\u753b\u50cf\u306e\u30ea\u30b5\u30a4\u30ba\u304c\u7d42\u308f\u3063\u3066\u306a\u3044\u306e\u306b\u9001\u4fe1\u30dc\u30bf\u30f3\u304c\u62bc\u305b\u3066\u3057\u307e\u3046\u300d<\/strong>\u3068\u3044\u3046\u72b6\u6cc1\u304c\u3067\u304d\u3066\u3057\u307e\u3046\u308f\u3051\u3067\u3059\u3002\u30d6\u30e9\u30a6\u30b6\u3092\u5b9f\u884c\u3059\u308b\u30c7\u30d0\u30a4\u30b9\u304c\u30ed\u30fc\u30b9\u30da\u30c3\u30af\u306e\u5834\u5408\u306f\u7279\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u3067\u3001\u6c17\u3092\u3064\u3051\u308b\u5fc5\u8981\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001true \/ false \u306e\u5909\u6570\u3092\u3072\u3068\u3064\u4f5c\u308a\u3001\u30ea\u30b5\u30a4\u30ba\u304c\u5b8c\u4e86\u3059\u308b\u307e\u3067\u306f\u9001\u4fe1\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3067\u304d\u306a\u304f\u3059\u308b\u3068\u3044\u3046\u65b9\u6cd5\u3092\u79c1\u306f\u3088\u304f\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff08HTML\u90e8\u5206\uff09<\/p>\n<pre>&lt;input type=\"file\" accept=\"image\/*\" <strong>:disabled=\"isResizing\"<\/strong> multiple @change=\"onImageChange\"&gt;<\/pre>\n<p>\uff08JavaScript\u90e8\u5206\uff09<\/p>\n<pre>data: {\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>isResizing: false<\/strong>\r\n},<\/pre>\n<pre>onImageChange(e) {\r\n\r\n    <strong>this.isResizing = true;<\/strong>\r\n    \r\n    \/\/ \u7701\u7565\r\n\r\n    for(let file of files) {\r\n\r\n        let reader = new FileReader();\r\n        reader.readAsDataURL(file);\r\n        reader.onload = (e) =&gt; {\r\n\r\n            let img = new Image();\r\n            img.onload = () =&gt; {\r\n\r\n                \/\/ \u7701\u7565\r\n\r\n                ctx.canvas.toBlob((blob) =&gt; {\r\n\r\n                    \/\/ \u7701\u7565\r\n\r\n<strong>                    if(this.smallImages.length == files.length) {<\/strong>\r\n\r\n<strong>                        this.isResizing = false;    \/\/ \u30ea\u30b5\u30a4\u30ba\u5b8c\u4e86\uff01<\/strong>\r\n\r\n<strong>                    }<\/strong>\r\n\r\n                }, file.type, 1);\r\n\r\n            };\r\n            img.src = e.target.result;\r\n\r\n        };\r\n\r\n    }\r\n\r\n}<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u753b\u50cf\u306e\u30ea\u30b5\u30a4\u30ba\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u9593\u306f<code>input<\/code>\u306e<code>disabled<\/code>\u304c\u6709\u52b9\u306b\u306a\u3063\u3066\u30dc\u30bf\u30f3\u304c\u30af\u30ea\u30c3\u30af\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002\uff08\u304a\u597d\u307f\u3067<code>v-if<\/code>\u3092\u4f7f\u3063\u3066\u300c\u30ea\u30b5\u30a4\u30ba\u4e2d&#8230;\u300d\u306a\u3069\u306e\u30c6\u30ad\u30b9\u30c8\u3068\u8868\u793a\u3092\u5207\u308a\u66ff\u3048\u3066\u3082\u3044\u3044\u3067\u3057\u3087\u3046\u3002\uff09<\/p>\n<h1>Laravel\u90e8\u5206<\/h1>\n<p>\u3067\u306f\u6700\u5f8c\u306b\u30c7\u30fc\u30bf\u9001\u4fe1\u3059\u308b\u5148\u306eLaravel\u90e8\u5206\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>public function resize_ajax(Request $request) {\r\n\r\n    <strong>if($request-&gt;has('images')) {<\/strong>\r\n\r\n<strong>        foreach ($request-&gt;images as $photo) {<\/strong>\r\n\r\n<strong>            $photo-&gt;store('images'); \/\/ storage\/app\/images\u30d5\u30a9\u30eb\u30c0\u306b\u4fdd\u5b58<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n}<\/pre>\n<p>\u4e2d\u8eab\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001<code>images<\/code>\u3068\u3044\u3046\u30c7\u30fc\u30bf\uff08\u4e2d\u8eab\u306f\u753b\u50cf\u306e\u30c7\u30fc\u30bf\u3067\u3059\u304c\u3001\u914d\u5217\u306a\u306e\u3067\u3001<code>hasFile()<\/code>\u306f\u4f7f\u3063\u3066\u3044\u307e\u305b\u3093\uff09\u304c\u5b58\u5728\u3057\u3066\u3044\u308b\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u3082\u3057\u898b\u3064\u304b\u3063\u305f\u5834\u5408\u306f\u30eb\u30fc\u30d7\u3092\u4f7f\u3063\u3066\u3072\u3068\u3064\u305a\u3064\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<h1>\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001Laravel\u90e8\u5206\u306f\u3054\u81ea\u8eab\u3067\u5b9f\u88c5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=3586&amp;tmstv=1777536551\" rel=\"nofollow\" id=\"download-link-3586\" data-redirect=\"false\" >\n\t\u5927\u304d\u306a\u753b\u50cf\u3092JavaScript\u3067\u30ea\u30b5\u30a4\u30ba\u3057\u3066\u304b\u3089Ajax\u9001\u4fe1<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u30b9\u30de\u30db\u3084PC\u306a\u3069\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u9078\u629e\u3057\u305f\u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba\u3057\u3066\u304b\u3089\u9001\u4fe1\u3059\u308b\u30c6\u30af\u30cb\u30c3\u30af\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u65b9\u6cd5\u3092\u4f7f\u3046\u3068\u3001\u4ee5\u4e0b\uff13\u3064\u306e\u30e1\u30ea\u30c3\u30c8\u304c\u30b2\u30c3\u30c8\u3067\u304d\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u753b\u50cf\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u304c\u9ad8\u901f\u306b\u306a\u308b<\/li>\n<li>\u30b9\u30de\u30db\u306a\u3069\u306e\u901a\u4fe1\u5236\u9650\u306b\u512a\u3057\u304f\u306a\u308b<\/li>\n<li>\u30b5\u30fc\u30d0\u30fc\u5074\u306e\u8ca0\u8377\u304c\u6e1b\u308b<\/li>\n<\/ul>\n<p>\u9006\u306b\u30c7\u30e1\u30ea\u30c3\u30c8\u3068\u306a\u308b\u3068\u3001\u753b\u50cf\u3092\u9078\u629e\u3057\u3066\u304b\u3089\u9001\u4fe1\u53ef\u80fd\u306b\u306a\u308b\u307e\u3067\u5c11\u3057\u3060\u3051\u6642\u9593\u304c\u304b\u304b\u308b\u3063\u3066\u3053\u3068\u3060\u3051\u3067\u3059\u304c\u3001\u6700\u8fd1\u306e\u30c7\u30d0\u30a4\u30b9\u306f\u9ad8\u6a5f\u80fd\u306a\u306e\u3067\u3053\u3061\u3089\u3082\u3042\u307e\u308a\u6c17\u306b\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u3053\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3067\u7701\u529b\u5316\u3057\u305f\u30a6\u30a7\u30d6\u958b\u767a\u3092\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u203b \u306a\u304a\u3001Vue\u3067Ajax\u9001\u4fe1\u3059\u308b\u305f\u3081\u306eJS\u30e9\u30a4\u30d6\u30e9\u30ea\u300c<a href=\"https:\/\/github.com\/SUKOHI\/v-api-form\" target=\"_blank\" rel=\"noopener noreferrer\">v-api-form<\/a>\u300d\u306b\u3082\u4eca\u56de\u306e\u30ea\u30b5\u30a4\u30ba\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u3088\u308d\u3057\u3051\u308c\u3070\u4f7f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-417 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png\" alt=\"\" width=\"370\" height=\"220\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9-300x178.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593 wordpress\u307f\u305f\u3044\u306a\u30c9\u30e9\u30c3\u30b0\u30fb\u30a2\u30f3\u30c9\u30fb\u30c9\u30ed\u30c3\u30d7\u3092Vue\u3067\u5b9f\u88c5\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u8a18\u4e8b\u306e\u76ee\u7684\u306f\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u30c9\u30e9 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=3578\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u5927\u304d\u306a\u753b\u50cf\u3092JavaScript\u3067\u30ea\u30b5\u30a4\u30ba\u3057\u3066\u304b\u3089Ajax\u9001\u4fe1\u3059\u308b\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":3593,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,3,12,97],"tags":[35],"class_list":["post-3578","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-laravel","category-vue-js","category-97","tag-ajax"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3578"}],"version-history":[{"count":10,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3578\/revisions"}],"predecessor-version":[{"id":3618,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3578\/revisions\/3618"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/3593"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}