Forum: Inkscape Batch resize of .svg files.

812ca5f14662dfd8426d2e29be2e5342?d=identicon&s=25 Gian Paolo Mureddu (Guest)
on 2008-09-25 21:34
(Received via mailing list)
Hi list.

I was wondering if I could perform a batch resize of many small .svg
files using Inkscape's command-line arguments? The --help doesn't state
much about this, and the only options having to do with size seem to be
width and height, or should I use something else like ImageMagik?


I'm on Linux, by the way.
C53fc1a55a7e1d09adda245cf20e9ff0?d=identicon&s=25 Terry Brown (Guest)
on 2008-09-25 21:43
(Received via mailing list)
On Thu, 25 Sep 2008 12:18:47 -0500
Gian Paolo Mureddu <thetargos@gmail.com> wrote:

> I was wondering if I could perform a batch resize of many small .svg
> files using Inkscape's command-line arguments? The --help doesn't
> state much about this, and the only options having to do with size
> seem to be width and height, or should I use something else like
> ImageMagik?

Can you explain a bit more what you're trying to do?  Is the desired
output .svg files, or .png/.gif/.jpg/whatever?

Cheers -Terry
812ca5f14662dfd8426d2e29be2e5342?d=identicon&s=25 Gian Paolo Mureddu (Guest)
on 2008-09-25 22:01
(Received via mailing list)
Terry Brown
escribió:>
> Can you explain a bit more what you're trying to do?  Is the desired
> output .svg files, or .png/.gif/.jpg/whatever?
>
> Cheers -Terry
>
>
I'm sorry, I should have been more specific.

I want to batch resize a large number of .svg files _into_ scaled up
.svg files, without having to open each individual file, resize and
save. Is it possible as command line arguments or through another
program like one of ImageMagick?
C53fc1a55a7e1d09adda245cf20e9ff0?d=identicon&s=25 Terry Brown (Guest)
on 2008-09-25 22:14
(Received via mailing list)
On Thu, 25 Sep 2008 12:53:49 -0500
Gian Paolo Mureddu <thetargos@gmail.com> wrote:

> I want to batch resize a large number of .svg files _into_ scaled up
> .svg files, without having to open each individual file, resize and
> save. Is it possible as command line arguments or through another
> program like one of ImageMagick?

The automatically changing the file part is easy enough with a variety
of tools like python or xsltproc or others, which are all readily
available in linux.  The part I'm not sure about is the easiest way to
apply a scaling effect to a whole SVG file, that's something that
requires more knowledge about SVG structure.

http://www.w3.org/TR/SVG11/coords.html

I think the safest route is something like changing the file from this:

<svg>
  <metadata/>
  <defs/>
  <sodipodi:namedview/>
  <blah1/>
  <blah2/>
  <blah3/>
</svg>

to:

<svg>
  <metadata/>
  <defs/>
  <sodipodi:namedview/>
  <g transform="scale(2.0)">
    <blah1/>
    <blah2/>
    <blah3/>
  </g>
</svg>

i.e. grouping all the "content" part of the document and applying a
scaling factor to it.

The two possible problems (which might not be problems) are (a) telling
the difference between content and non-content (preamble / setup
elements) and (b) how this would impact Inkscapes layers.  I suspect
(b) won't matter for your application and (a) could probably be done by
just assuming everything except <metadata/>, <defs/>, and
<sodipodi:namedview/> is content.

If there's an easier way or a fatal flaw in the above maybe someone can
chime in?

Cheers -Terry
C53fc1a55a7e1d09adda245cf20e9ff0?d=identicon&s=25 Terry Brown (Guest)
on 2008-09-25 22:25
(Received via mailing list)
Attachment: bigger.xsl (799 Bytes)
On Thu, 25 Sep 2008 12:53:49 -0500
Gian Paolo Mureddu <thetargos@gmail.com> wrote:

> I want to batch resize a large number of .svg files _into_ scaled up
> .svg files, without having to open each individual file, resize and
> save. Is it possible as command line arguments or through another
> program like one of ImageMagick?

I haven't tested it very hard but the attached bigger.xsl (XSLT) script
seems to work.  Invocation is something like:

xsltproc --stringparam scale 2.5 bigger.xsl in.svg >out.svg

or for all the .svg files in the current directory:

for i in *.svg; do xsltproc --stringparam scale 2.5 bigger.xsl $i
>bigger_$i; done

(all on one line)

If you want to make things smaller use a scale value smaller than 1.0

If your system doesn't have xsltproc, then for Ubuntu at least run:

  sudo apt-get install xsltproc

Hope that helps, Cheers -Terry
57ff4cadf680e03b0e624d93b4cf0192?d=identicon&s=25 Andreas Neumann (Guest)
on 2008-09-25 22:44
(Received via mailing list)
Hi Gian Paolo,

SVG files are scalable if they are exported correctly. The problem is
that Inkscape (like many other drawing apps (Corel, Illustrator, etc.)
works "paper-oriented" and not "screen oriented".

In a proper screen oriented SVG you would use the following root
element, which scales nicely and automatically in any browser:

<svg width="100%" height="100%" viewBox="0 0 1024 768">
<!-- use your own paper size in the viewbox; some content -->
</svg>

So I suggest you pull out the absolute width and height values that
Inkscape produces and write them to the viewBox attribute.

Inkscape should have an option for this, something like "Publish SVG for
the Web". It is very simple to do.

Hope this helps,
Andreas
F315ca6eec6e3761a0cad7b9beb615aa?d=identicon&s=25 bulia byak (Guest)
on 2008-09-26 14:21
(Received via mailing list)
On Thu, Sep 25, 2008 at 3:22 PM, Terry Brown <terry_n_brown@yahoo.com>
wrote:
> I tried just now "add a transform= attribute to the root svg
> tag" (transform="scale(2.)") and that seemed to have no effect on the
> file as loaded by inkscape.

I might be wrong in saying it's possible, or it may be an Inkscape
bug. In any case, it's always possible just to add another level of
<g> with transform - it's trivial in XSLT, though a little more
difficult in other scripting languages that are not XML-based.

>  Changing the width/height attributes of
> the root svg tag is probably simpler than what I just suggested in the
> previous post, although not a lot, if you're using xslt.

That would just change the canvas size and not scale objects.

--
bulia byak
Inkscape. Draw Freely.
http://www.inkscape.org
C53fc1a55a7e1d09adda245cf20e9ff0?d=identicon&s=25 Terry Brown (Guest)
on 2008-09-26 14:35
(Received via mailing list)
On Thu, 25 Sep 2008 15:09:55 -0300
"bulia byak" <buliabyak@gmail.com> wrote:

> If you really need it, I think it's easiest to do by a XSLT script
> that would add a transform= attribute to the root svg tag of all files
> and adjusts width/height.

I tried just now "add a transform= attribute to the root svg
tag" (transform="scale(2.)") and that seemed to have no effect on the
file as loaded by inkscape.  Changing the width/height attributes of
the root svg tag is probably simpler than what I just suggested in the
previous post, although not a lot, if you're using xslt.

I'm assuming the poster has some application where they want to import
lots of .svg files into an Inkscape project as clipart, and they're
all at the wrong size and have to be resized each time which would be
annoying.

Of course just changing the scale of the project into which you're
importing might be the easiest approach if that's the case.

Cheers -Terry
F315ca6eec6e3761a0cad7b9beb615aa?d=identicon&s=25 bulia byak (Guest)
on 2008-10-04 17:17
(Received via mailing list)
On Thu, Sep 25, 2008 at 2:53 PM, Gian Paolo Mureddu
<thetargos@gmail.com> wrote:
> I want to batch resize a large number of .svg files _into_ scaled up
> .svg files, without having to open each individual file, resize and
> save.

That's a bit weird, since SVG is vector it is rarely needed to resize
as a whole - you just embed it at a different size, or scale where you
imported it, or export it to a higher resolution. The "size" of an SVG
is just a hint.

If you really need it, I think it's easiest to do by a XSLT script
that would add a transform= attribute to the root svg tag of all files
and adjusts width/height. You can also try to do it via Inkscape verbs
from commandline, but we don't have a verb which scales to a given
extent (verbs cannot have arguments currently).

--
bulia byak
Inkscape. Draw Freely.
http://www.inkscape.org
812ca5f14662dfd8426d2e29be2e5342?d=identicon&s=25 Gian Paolo Mureddu (Guest)
on 2008-10-04 17:19
(Received via mailing list)
Terry Brown
escribió:> tag" (transform="scale(2.)") and that seemed to have no effect on the
> importing might be the easiest approach if that's the case.
>
> Cheers -Terry

Actually I'm designing some gliphs to be used as part of a font, the
problem is that all the gliphs have to be a separate .svg file to be
then imported into FontForge. We ran into a problem where the scale of
the .svg's is too small and there's no easy way to resize them in
FontForge. We went with .svg rather than bitmap files because they are
already vector graphics which can be directly manipulated in FontForge,
however we are taking too much time doing the resize of the files, and
we don't seem to be able to attain a consistent scale (i.e. all
characters of the same/consistent size). Hence rather than opening up
each individual gliph (over 180 individual files, thus far), I thought
if it could be possible to apply a batch "transform" to change the size
of the files "in one pass". That was my original question, rather than a
"representation" scale of the SVGs (by a given factor).
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.