Issue with SVG image and clip-path

Archived from the Transloadit support forum. Originally posted on April 24, 2013; details may be outdated, see our docs for current behavior. Original thread

Hello,

When trying to convert an SVG to a JPEG with an image and a clip-path applied to it, the position and size are a bit off.
Here is the assembly Id: REDACTED

In the resulting JPEG, the grey at the top of the image is part of a rectangle that should match the size and position of the image, so that the image should completely cover it.

Also the image in the resulting JPEG is pixelated, but that can be fixed on my end by linking to an image of similar size.
In that example the image is 1800x1200px scaled in SVG.

Hi Levy,

For starters, sorry for the wait, this required some research on our part. Several issues concerning fonts, svg, etc in your account were pointed out to me, I will address each one of them individually here now.

a)

convert: Non-conforming drawing primitive definition `Arial''' @ draw.c/DrawImage/3123.

assembly: https://transloadit.com/assemblies/view/REDACTED solution: please use Arial, and not 'Arial' as a font-name. Or our software will try to look for e.g. /usr/share/fonts/truetype/'Arial'.ttf.

b)

convert: Non-conforming drawing primitive definition `Futura-Medium''' @ draw.c/DrawImage/3123.

assembly: https://transloadit.com/assemblies/view/REDACTED solution: The font is double quoted, just like Arial in a), but additionally, we do not support the Futura-Medium font yet. I’ve added a list of the fonts that we do support here now: https://transloadit.com/docs/supported-formats-codecs#image-fonts.
If you want we could add more fonts depending on demand & licensing.

c)

convert: unable to open image `../img/03.jpg': No such file or directory @ blob.c/OpenBlob/2439.

assembly: https://transloadit.com/assemblies/view/REDACTED solution: We don’t have the image ../image/03.jpg on our servers, maybe you could refer to external images like you do in assembly https://transloadit.com/assemblies/view/REDACTED ?
There you refer like so: xlink:href="http://svg.pinholepress.com.s3.amazonaws.com/20/13b78c66257e278c954b9a8a3465f0/03.jpg" vs this in assembly: xlink:href="../img/03.jpg".

d)

# no error message, but there is a gray tripe on the top of the image.

assembly: https://transloadit.com/assemblies/view/REDACTED
solution: I’m not sure, but it looks like what you are doing, is using a jpg, refer to that from an svg to resize it, then make a jpg of that again. Maybe you can use http/import and directly resize the jpeg? Because I think we’re hitting an Imagemagick limitation here caused by the fact that the transform="scale(0.3075) is not implemented accurately enough to get to match exact right size you specify earlier. But I’m not sure about this one and could use your input. However if I’m directly resizing http://svg.pinholepress.com.s3.amazonaws.com/20/13b78c66257e278c954b9a8a3465f0/03.jpg to width="306px" height="396px" using our image/resize bot it looks good. So maybe you can lose the svg wrapper here.

Note that I made improvements to our font handling over the past week (and added documentation for it) that we did not have before, so some things will work now, that did not work at the time of the assemblies. You could hit the Replay button in your account to try again.

Hope this helps, let me know how things work out,
and at any rate, have a magnificent weekend!

Kind regards,
Kevin

Hello Kevin,

Thanks for the in-depth answers. I’ll try to answer or give additional info about each of the point using your list.

a) & b) Regarding the fonts that we’ll be using, I do not know yet. I’m using these SVGs for testing purposes and chose font-families that I have and don’t have installed on my computer. Also, thanks for the supported font list provided, I’ll try to limit myself to those for now.
As for the font-family being wrapped in apostrophes, that’s how Adobe Illustrator exports the SVG file, and since SVG uses the same notation standard that they use for CSS it makes sense to have it the apostrophes or double quotes in case of a 2 word font name. I could remove the apostrophes when I parse the SVG, but won’t, for example ‘Helvetica Neue’, create problems on your end?
Let me know what are your thoughts on this issue.

c) Yeah, this was my bad, remembered about the relative path while it was uploading.

d) This is a tricky one, I admit the SVG uploaded isn’t the best example. This example only has an image, but there could be SVGs with images (one or more), design elements and text.
Tested again, and the scale seems to be spot on, but I think the x, y, width, height and translate values are being converted to integers.
I have a question regarding this point. It looks like your bot is using the width and height specified as attributes of the SVG tag, if I want to create a larger image (which we will need at some point), how is your bot going to handle the SVG?
Convert it to a JPEG with the specified width and height first than resize it, or scale the SVG and then convert it?

Hope this info helps in any way, if you have any more questions, just let me know.
Thanks again for your help.

Regards,
~ Levy

Hey Levy,

Just wanted to let you know that I’m looking into your matters and will get back to you shortly.

Kind regards,
Kevin

Hey Levy,

Let’s go over the individual issues again.

a) & b) there are single quotes in the font names.

As you can see in assembly https://transloadit.com/assemblies/REDACTED I double checked, and even though we support "Arial" now, we don’t support "'Arial'". If you open the .svg you see the fontnames are quoted twice.
As you can read in http://www.w3.org/TR/SVG/fonts.html, it’s not correct to use fill="#FFFFFF" font-family="'Arial'". As far as I can tell you can only use extra single quotes inside a <style> block. e.g.:

<style type="text/css">
      <![CDATA[
        @font-face {
          font-family: 'Arial';

At any rate, our encoding software does not support it. Is there a way for you to strip these superfluous single quotes? Maybe it turns out it’s just because someone actually entered 'Arial' into Illustrator somewhere, as they copy-pasted it from a <style> block somewhere? Illustrator then gracefully handles this, but other image software is having a harder time with it. Just a thought.

c) refer to local images

Alright that’s solved then. Thanks for figuring this out with me.

d) gray stripe when scaling jpegs inside an svg

You might be right about the integers. The resizing is done by our encoding software. The .svg is interpreted, and once rendered internally (including the transform), the pixels are saved as .jpg. It would be possible to chain multiple /image/resize steps together in 1 assembly, though quite hard as you’d need to refer to s3 paths that are created in the same assembly. Also, since s3 is eventually consistent, this could theoretically cause race conditions. Using Transloadit’s tmp urls might be able to deal with this, but that really needs some careful thought, let me know if we need to invest some more into this direction. Another thing we could investigate is how newer versions of our software deal with the svg transforms. If we get better results with that in on an isolated testmachine, it will take some time to roll that out into production though due to backwards compatibility issues. Let me know which direction you’d like to take this.

Kind regards,
Kevin

Hello Kevin,

Sorry for not answering sooner, but was away on vacation.
I will look over all this early next week and get back to you as soon as I can.

Apologies for the delay.

Closing this for now. Please feel free to re-open the ticket if you have further questions.

Also, please consider adding me on Skype to discuss things further. My Skype username is “transloadit_tim”.

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos