Crop SVG file & shrink filesize

Post questions on how to use or achieve an effect in Inkscape.
SecondStar
Posts: 2
Joined: Wed Jul 10, 2013 7:28 am

Crop SVG file & shrink filesize

Postby SecondStar » Wed Jul 10, 2013 10:33 am

Hi,
I'm very new to vector graphics and something I assumed would be very easy to do is more complicated than expected.
What I want to achieve is very simple: to crop a small part of a svg file, which would be both smaller in shape and in filesize.

My initial file is a svg world map, 340k

Image

What I want as a result is just this, just a part of the map with India & China:
Image

I had a try, tried a rectangular selection, then file>Document properties>resize page to selection...
It gave me the selection I wanted.... Problem is the svg file with only southern asia was 440ko, bigger than the original file!
Opening the file with a text editor showed it retained all the code of the original file (shapes & labels of the USA, etc...)

Is there a way to export just part of a svg file, retaining the properties while removing everything unnecessary?
In this case with the original world map at 360 ko, the southern asia crop/file should at least take less than 100ko.

I joined the original world map on dropbox, if this can be of any help: https://www.dropbox.com/s/e8xrz36fza9nn63/WorldMap.svg

If anyone know how this seemingly simple thing can be achieved in Inkscape, I'm listening...
Thanks!

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Crop SVG file & shrink filesize

Postby Lazur » Fri Jul 12, 2013 8:39 am

Welcome aboard!

That is, the basic difference between vector and raster images.
There are no data for each pixel of the image provided in the codes.
As you could see, all the objects are paths defined by nodes.
It's like wire that's been bent to the right shape.
You can use a clipping mask to hide parts of the document at a rendering,
but hopefully that won't delete the data not used.
So if you want only a part of a path, or let's say, "wire", you will have to edit them separetely.

On the attached svg most of the unwanted parts are deleted -based on your image-, resulting in a smaller file.
There are two choices to make it cleaner: clipping more of the unwanted parts off with a clipping mask -which only modifies the rendering,
or to cut manually off the parts of each country with another path -which would result in a smaller file size, by literally cutting them to new shapes, with less nodes.
Attachments
WorldMap2.svg
(33.08 KiB) Downloaded 221 times

SecondStar
Posts: 2
Joined: Wed Jul 10, 2013 7:28 am

Re: Crop SVG file & shrink filesize

Postby SecondStar » Fri Jul 12, 2013 10:45 am

Thank you for everything Lazur: taking the time to explain and edit the file.

Had a look at the file, it's exactly what I was after: smaller in size, with only the necessary stuff, and the names/properties of shapes who matters are preserved.
The latter was very important, as my svg goes through a software which allows to set the viewbox only on what's necessary (like my second screenshot) and edit/build things from the countries properties.

For a moment I was afraid I couldn't do what I wanted but it seems possible. Now the real work begins, as I had a lot of ideas planned that would rely on svg.
I'm gonna try to find my marks in Inkscape and come up with the same trimmed file.
I'll let you know how I succeed -- or not ;)

Thanks again!


Return to “Help with using Inkscape”