I have a SVG which contains rectangles with other shapes. How can I extract all rectangle details(co-ordinates, height and width)? Find below svg details where I kept only one rectangle for reference.

<?xml version="1.0" encoding="UTF-8"?>
<svg width="301.36mm" height="174.36mm" viewBox="0 0 1139 659" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g fill="none" stroke="black" stroke-width="1" fill-rule="evenodd" stroke-linecap="square" stroke-linejoin="bevel">
            <clipPath id="clip27">
                <path d="M-272.5,-2.5 L866.5,-2.5 L866.5,656.5 L-272.5,656.5 L-272.5,-2.5 z"/>
        </defs><g clip-path="url(#clip27)" fill="none" opacity="1" stroke="#000000" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="2" stroke-opacity="1" stroke-width="1" transform="matrix(1,0,0,1,272.5,2.5)">
            <path d="M0,0 L110,0 L110,176 L0,176 L0,0 z" fill-rule="evenodd" vector-effect="none"/>
            <clipPath id="clip34">
                <path d="M0,0 L112,0 L112,15 L0,15 L0,0 z"/>
        </defs><g clip-path="url(#clip34)" fill="none" opacity="1" stroke="#000000" stroke-linecap="square" stroke-linejoin="bevel" stroke-opacity="1" stroke-width="1" transform="matrix(1,0,0,1,271.07,180)">
            <text fill="#000000" fill-opacity="1" font-family="Arial" font-size="10" font-style="normal" font-weight="400" stroke="none" textLength="109.859" x="1" xml:space="preserve" y="11">BoostDiagSlow_Release</text>
  • 1
    $\begingroup$ If the shapes are defined by just a series of line drawing commands (go to point X, draw to point Y, etc), there's not a simple way to know what is a "rectangle". It would be better if you could get the author of the file to use some naming conventions to tell you which things are "rectangles". $\endgroup$ Aug 29, 2022 at 15:35
  • $\begingroup$ Well, you could do this. Its not super practical though. As there are quite a bit of corner cases. $\endgroup$
    – joojaa
    Aug 30, 2022 at 5:56


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.