Last active
September 10, 2015 13:21
-
-
Save calvinfroedge/fad60de2e90371684d45 to your computer and use it in GitHub Desktop.
SVG masks / clipping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--<img class="svg-clipped" src="http://sarasoueidan.com/demos/css-svg-clipping/html-img-clipped-with-css-svg-clippath/flowers.jpg" style=""/>--> | |
<svg height="100" width="100"> | |
<defs> | |
<pattern id="img1" patternUnits="userSpaceOnUse" width="100" height="100"> | |
<image xlink:href="http://sarasoueidan.com/demos/css-svg-clipping/html-img-clipped-with-css-svg-clippath/flowers.jpg" x="0" y="0" width="100" height="100" /> | |
</pattern> | |
</defs> | |
<path fill="url(#img1)" stroke="#000000" stroke-width="0" stroke-miterlimit="" d="M 74.3243675,137.7170575 C 70.8806075,133.8579775 62.2817,126.3346375 55.2156925,120.99853 C 34.2796675,105.18807 31.43027,102.899975 22.9298095,95.07272 C 7.2586775,80.6426775 0.6034055,66.145215 0.62621195,46.48781 C 0.63733985,36.8918475 1.2914038,33.1948225 3.9786835,27.538495 C 8.53785825,17.94206675 15.253749,10.81116675 23.840013,6.44986425 C 29.9213625,3.36091875 32.920675,1.98855115 43.07612,1.9324059 C 53.6994425,1.8736974 55.9357775,3.11233675 62.1847975,6.54536475 C 69.790925,10.72394425 77.6197725,19.65429175 79.238105,25.9980125 L 80.23763,29.9161125 L 82.7025375,24.5199855 C 96.63158,-5.9732465 141.1021275,-5.5170275 156.57811,25.2778825 C 161.4875275,35.046895 162.02652,55.906175 157.67314,67.6561 C 151.9943225,82.9834425 141.3281375,94.6687325 116.671555,112.575245 C 100.50135,124.318655 82.20037,142.08671 80.9263875,144.5822525 C 79.4475175,147.479135 80.8558475,145.0362275 74.3243675,137.7170575 z"></path> | |
</svg> | |
<style type="text/css"> | |
html, body { margin: 0;padding:0;} | |
.svg-clipped { | |
-webkit-clip-path: url(#svgPath); | |
clip-path: url(#svgPath); | |
} | |
</style> | |
<!-- For scaling heart path | |
spaceSeparated = svgString.split(' '); | |
trans = function(s, factor){ | |
a = s.split(","); | |
return a.map(function(item){ | |
return parseFloat(item) * (factor || 1) | |
}).join(','); | |
} | |
reg = new RegExp(/[A-Za-z]/); | |
asArr = spaceSeparated.map(function(item){ | |
if(reg.test(item)) return item; | |
return trans(item, 0.5); | |
}); | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment