On Tue, May 14, 2013 at 11:19 AM, Jan Gerber <jger...@wikimedia.org> wrote:

> for the Score extension it would be nice to output SVG images, the SVG
> images produced by lilypond have lots of white space (it outputs paper
> sheets), covert can give the outer bound and offset of the area we want to
> display:
>
> I.e. for http://upload.wikimedia.org/wikipedia/test2/d/d5/ScoreSVGTest.svg
>
> $ convert ScoreSVGTest.svg -trim info:-
> ScoreSVGTest.svg SVG 434x267 744x1052+27+23 16-bit DirectClass 0.010u
> 0:00.009
>


Handy that you can get trim info out of convert, that's probably easier
than using an XML parser and trying to understand all the paths and
transformations manually. :)



> If SVG is scaled to 744x1052, we want to crop it to 434x267 starting at
> (27, 23)
>
> Does anyone know how to translate this into the width/height/viewBox
> properties in SVG?
>

So, there's two things you probably want to modify:
* the width and height attributes on the <svg> element
* the viewBox attribute on the <svg> element

On the sample file you'll see them like this:

<svg ... width="210.00mm" height="297.00mm" viewBox="0 0 119.5016 169.0094">

The 'width' and 'height' attributes set the default physical size of the
image, in this case an A4 sheet of paper. Note that these apparently can
include units; if units are unspecified I think they default to CSS pixels.
Yay!

The 'viewBox' attribute lists the *internal* coordinate space that fits in
that physical box, as "origin-x origin-y width height" Unfortunately it's
not the same units as the physical width/height here, but luckily the
initial origin is at 0,0 in these, so it makes the math simpler. ;)

You should be able to scale your target coordinates from ImageMagick's
pixel counts into both the physical size and internal coordinate spaces,
then set the width/height and viewBox attributes to match.

-- brion
_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to