• svg image size

    From saitology9@21:1/5 to All on Wed Feb 22 10:36:26 2023
    Hello,

    Is there a way to get the width/height of svg images without creating
    them as images first?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to [email protected] on Wed Feb 22 16:27:36 2023
    SVG files are just XML (text) files. Load one of the XML libraries and read/parse the XML (I have a nifty SNIT class for that in my ModelRRSystem: https://github.com/RobertPHeller/ModelRRSystem/blob/master/trunk/Scripts/Common/ParseXML.tcl).
    In the <svg> tag are attributes for image size and coordinate space in use -- width, height, and viewBox.

    At Wed, 22 Feb 2023 10:36:26 -0500 saitology9 <[email protected]> wrote:


    Hello,

    Is there a way to get the width/height of svg images without creating
    them as images first?



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to [email protected] on Wed Feb 22 20:40:05 2023
    saitology9 <[email protected]> wrote:
    On 2/22/2023 11:27 AM, Robert Heller wrote:
    SVG files are just XML (text) files. Load one of the XML libraries
    and read/parse the XML (I have a nifty SNIT class for that in my
    ModelRRSystem:
    https://github.com/RobertPHeller/ModelRRSystem/blob/master/trunk/Scripts/Common/ParseXML.tcl).
    In the <svg> tag are attributes for image size and coordinate space
    in use -- width, height, and viewBox.


    Thank you. The width/height seem to be optional as some svg files
    don't have them. I am not sure about the viewbox property.

    Keep in mind that the notion of a width/height of an SVG is somewhat of
    an odd question. The "S" in SVG stands for scalable and the "V" for
    vector, and because they are scalable vectors, they can be any size you
    want them to be. The only meaningful value for an SVG would be the
    required aspect ratio to represent it without distortion.

    Reality is many will indicate a "size" value in the xml, but that
    should be taken more as a "suggestion" than a hard fact as such a size
    would be for a bit-map graphic image.

    Wouldn't a regexp be a better solution here?

    Not as a general XML parsing solution. Regular expressions are not
    expressive enough to fully parse the entirety of the XML specification.

    With that said, for a specific XML variant (i.e., SVG's) and for
    looking for a very specific attribute therein (a suggested
    width/height, should it exist) you /can/ use a regex and it should work
    in most instances.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to [email protected] on Wed Feb 22 21:14:40 2023
    At Wed, 22 Feb 2023 15:24:42 -0500 saitology9 <[email protected]> wrote:


    On 2/22/2023 11:27 AM, Robert Heller wrote:
    SVG files are just XML (text) files. Load one of the XML libraries and read/parse the XML (I have a nifty SNIT class for that in my ModelRRSystem: https://github.com/RobertPHeller/ModelRRSystem/blob/master/trunk/Scripts/Common/ParseXML.tcl).
    In the <svg> tag are attributes for image size and coordinate space in use --
    width, height, and viewBox.


    Thank you. The width/height seem to be optional as some svg files don't
    have them. I am not sure about the viewbox property.

    The width/height propertiesare sometimes used to specific a *physical* size
    (in inches or millimeters, etc.). The viewBox property can be used to specific the coordinate bounding box, and thus the mapping of the coordinates in the body of the file to "screen" (or paper or whatever) coordinates.

    For example this Fritzing breadboard image:

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Generator: FritzingPartsSVGEditor 0.0.2 on x86_64-unknown-linux-gnu (BreadboardEditor) -->
    <svg viewBox="0.000000 0.000000 47.565543 33.295880" width="4.756554mm" x="0mm" height="3.329588mm" y="0mm" version="1.1" xml:space="preserve">
    <g id="breadboard">
    <circle fpe:gid="1" cx="17.266292134831453" cy="16.647940074906355" r="16.0" fill="none" stroke="black" stroke-width="2.0"/>
    <circle fpe:gid="2" id="connector1pin" cx="17.266292134831453" cy="16.64794007490637" r="4.999999999999999" fill="black"/>
    <circle fpe:gid="3" id="connector2pin" cx="42.66629213483144" cy="16.64794007490637" r="4.9999999999999964" fill="black"/>
    </g>
    </svg>

    defines a part that is "physically" 4.756554mm by 3.329588mm, with the coordinates in tenths of a mm.


    Wouldn't a regexp be a better solution here?



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Robert Heller on Wed Feb 22 15:24:42 2023
    On 2/22/2023 11:27 AM, Robert Heller wrote:
    SVG files are just XML (text) files. Load one of the XML libraries and read/parse the XML (I have a nifty SNIT class for that in my ModelRRSystem: https://github.com/RobertPHeller/ModelRRSystem/blob/master/trunk/Scripts/Common/ParseXML.tcl).
    In the <svg> tag are attributes for image size and coordinate space in use -- width, height, and viewBox.


    Thank you. The width/height seem to be optional as some svg files don't
    have them. I am not sure about the viewbox property.

    Wouldn't a regexp be a better solution here?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to Rich on Wed Feb 22 21:14:40 2023
    At Wed, 22 Feb 2023 20:40:05 -0000 (UTC) Rich <[email protected]d> wrote:


    saitology9 <[email protected]> wrote:
    On 2/22/2023 11:27 AM, Robert Heller wrote:
    SVG files are just XML (text) files. Load one of the XML libraries
    and read/parse the XML (I have a nifty SNIT class for that in my
    ModelRRSystem:
    https://github.com/RobertPHeller/ModelRRSystem/blob/master/trunk/Scripts/Common/ParseXML.tcl).
    In the <svg> tag are attributes for image size and coordinate space
    in use -- width, height, and viewBox.


    Thank you. The width/height seem to be optional as some svg files
    don't have them. I am not sure about the viewbox property.

    Keep in mind that the notion of a width/height of an SVG is somewhat of
    an odd question. The "S" in SVG stands for scalable and the "V" for
    vector, and because they are scalable vectors, they can be any size you
    want them to be. The only meaningful value for an SVG would be the
    required aspect ratio to represent it without distortion.

    Reality is many will indicate a "size" value in the xml, but that
    should be taken more as a "suggestion" than a hard fact as such a size
    would be for a bit-map graphic image.

    Wouldn't a regexp be a better solution here?

    Not as a general XML parsing solution. Regular expressions are not expressive enough to fully parse the entirety of the XML specification.

    With that said, for a specific XML variant (i.e., SVG's) and for
    looking for a very specific attribute therein (a suggested
    width/height, should it exist) you /can/ use a regex and it should work
    in most instances.

    Tcl *does* have several XML parsing libraries, so it is not really to parse things properly. If one is dealing with svgs from a variaty of sources,
    using regexp is going to be hard to get working in all cases of legit SVG files, since different programs will include (or not) the attributes one is looking for in different places or order.




    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Robert Heller on Wed Feb 22 17:23:47 2023
    On 2/22/2023 4:14 PM, Robert Heller wrote:
    At Wed, 22 Feb 2023 20:40:05 -0000 (UTC) Rich <[email protected]d> wrote:

    With that said, for a specific XML variant (i.e., SVG's) and for
    looking for a very specific attribute therein (a suggested
    width/height, should it exist) you /can/ use a regex and it should work
    in most instances.

    Tcl *does* have several XML parsing libraries, so it is not really to parse things properly. If one is dealing with svgs from a variaty of sources, using regexp is going to be hard to get working in all cases of legit SVG files, since different programs will include (or not) the attributes one is looking for in different places or order.





    Thank you both for the info. I knew about svg files but I hadn't worked
    with them before. These are quite small svg image files so really either
    option would work fine.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)