snipt

Ctrl+h for KB shortcuts

Text only

Allow Cross-Domain Images with CORS

# Images are usually cool to serve from a different domain but if you want access 
# to their data with canvas, you're in trouble.  
# This snippet allows you to get raw image data via canvas:

<IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
        <FilesMatch "\.(cur|gif|ico|jpe?g|png|svgz?|webp)$">
            SetEnvIf Origin ":" IS_CORS
            Header set Access-Control-Allow-Origin "*" env=IS_CORS
        </FilesMatch>
    </IfModule>
</IfModule>

# After you get that image data, you can add filters and more.  
# Here's a tutorial showing you how to convert the image to canvas:
# http://davidwalsh.name/convert-canvas-image

http://davidwalsh.name/html5-boilerplate-htaccess
https://snipt.net/embed/539ca303c6a03bd5c0712f0a35800818/
/raw/539ca303c6a03bd5c0712f0a35800818/
539ca303c6a03bd5c0712f0a35800818
text
Text only
18
2019-08-19T09:49:54
True
False
False
Dec 16, 2013 at 11:53 AM
/api/public/snipt/100829/
allow-cross-domain-images-with-cors
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a># Images are usually cool to serve from a different domain but if you want access </span><span id="L-2"><a name="L-2"></a># to their data with canvas, you&#39;re in trouble. </span><span id="L-3"><a name="L-3"></a># This snippet allows you to get raw image data via canvas: </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>&lt;IfModule mod_setenvif.c&gt; </span><span id="L-6"><a name="L-6"></a> &lt;IfModule mod_headers.c&gt; </span><span id="L-7"><a name="L-7"></a> &lt;FilesMatch &quot;\.(cur|gif|ico|jpe?g|png|svgz?|webp)$&quot;&gt; </span><span id="L-8"><a name="L-8"></a> SetEnvIf Origin &quot;:&quot; IS_CORS </span><span id="L-9"><a name="L-9"></a> Header set Access-Control-Allow-Origin &quot;*&quot; env=IS_CORS </span><span id="L-10"><a name="L-10"></a> &lt;/FilesMatch&gt; </span><span id="L-11"><a name="L-11"></a> &lt;/IfModule&gt; </span><span id="L-12"><a name="L-12"></a>&lt;/IfModule&gt; </span><span id="L-13"><a name="L-13"></a> </span><span id="L-14"><a name="L-14"></a># After you get that image data, you can add filters and more. </span><span id="L-15"><a name="L-15"></a># Here&#39;s a tutorial showing you how to convert the image to canvas: </span><span id="L-16"><a name="L-16"></a># http://davidwalsh.name/convert-canvas-image </span><span id="L-17"><a name="L-17"></a> </span><span id="L-18"><a name="L-18"></a>http://davidwalsh.name/html5-boilerplate-htaccess </span></pre></div> </td></tr></table>
htaccess, vhost