Local Hero Posted November 2, 2015 Share Posted November 2, 2015 I have many SVG files, and I want to be able to quickly display the Length and Width of the files in HTML. I know that I can do it in Illustrator, but I need to make changes on the web and check the size. There is a file located at www.LocalHeroMX.com/graphics4/images/models/cobracx50sr-2010-2015/lnp.svg What would I have to do to return the values of the height and width in either pixels or inches?Thanks for any help. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 2, 2015 Share Posted November 2, 2015 If you view the source of svg would see is an xml type file. <?xml version="1.0" encoding="utf-8"?> <!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1173.875px" height="594.142px" viewBox="0 0 1173.875 594.142" enable-background="new 0 0 1173.875 594.142" xml:space="preserve"> <path fill="#FFFFFF" stroke="#000000" stroke-width="2" stroke-miterlimit="10" d="M1147.098,198.556l-306-190c0,0-20-17-42,0 c-9.743,13.504-33.631,23.733-60.85,31.352l-1.056-11.608c-0.344-3.804-4.48-6.536-9.237-6.104L163.552,73.509 c-4.755,0.432-8.33,3.865-7.984,7.67l2.159,23.756c-60.039,5.679-103.227,9.563-109.629,9.621c-24.18,0.221-22.928,4.32-38,32 c-4.287,7.939-18.131,12.617,0,21c18.131,8.383,556,375,556,375s43.5,33,107,35c64.5,13.5,83.2,8,156,15s118-51,118-51 s180.5-203,213-261C1195.098,232.056,1147.098,198.556,1147.098,198.556z M285.098,195.056c-41,15-75.5,19.5-113,22 c-29.5,6-24-20-24-20s2.5-28.5,6-47s18-15,18-15s81-6.5,110,0C331.098,137.556,329.598,184.056,285.098,195.056z M631.598,255.056 c-14.359,0-26-11.641-26-26c0-14.359,11.641-26,26-26c14.359,0,26,11.641,26,26C657.598,243.415,645.957,255.056,631.598,255.056z" /> </svg> using simplexml be the best bet or can try using file_get_contents/curl and preg_match the svg tags content. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 2, 2015 Share Posted November 2, 2015 $xml = simplexml_load_file($svgimage); $data = $xml->attributes(); printf("%s x %s", $data->width, $data->height); Quote Link to comment Share on other sites More sharing options...
Local Hero Posted November 2, 2015 Author Share Posted November 2, 2015 That worked. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.