Skip to content

Instantly share code, notes, and snippets.

@innermond
Last active February 28, 2020 21:30
Show Gist options
  • Save innermond/e5750af0da6a8bef9b411f33e9574d01 to your computer and use it in GitHub Desktop.
Save innermond/e5750af0da6a8bef9b411f33e9574d01 to your computer and use it in GitHub Desktop.
svg element scales arround its center
$img = document.querySelector('image:nth-of-type(2)')
$svg = document.querySelector('svg')
k = 2.5
bb = $img.getBBox()
x = bb.x + bb.width/2
x *= (1-k)
y = bb.y + bb.height/2
y *= (1-k)
tsf = $svg.createSVGTransform()
tsf.setScale(k,k)
trans = $svg.createSVGTransform()
trans.setTranslate(x, y)
lst = $img.transform.baseVal
lst.appendItem(trans)
lst.appendItem(tsf)
lst.consolidate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment