Importing SVG images

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Importing SVG images

Post by richmond62 » Mon Apr 17, 2023 7:35 am

If an SVG image is imported via the 'import image' menu item any colours
get either lost or distorted:
-
SShot 2023-04-17 at 9.32.54.png
SShot 2023-04-17 at 9.32.54.png (24.54 KiB) Viewed 5478 times
-
While it is perfectly possible to do a "2 step job" by opening an SVG
in GIMP and exporting it as a PNG which is subsequently imported into LC
the scaleability is lost.
Attachments
Circle05-Orange.svg.zip
Original SVG image
(5.79 KiB) Downloaded 127 times

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: Importing SVG images

Post by stam » Mon Apr 17, 2023 8:06 am

This may be helpful for your purposes:
https://forums.livecode.com/viewtopic.php?f=8&t=37299

HTH
S.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1232
Joined: Thu Apr 11, 2013 11:27 am

Re: Importing SVG images

Post by LCMark » Mon Apr 17, 2023 11:40 am

The gradient is imported exactly as it should be as far as I can see (when using Import Image locally with the supplied svg file).

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing SVG images

Post by richmond62 » Mon Apr 17, 2023 11:43 am

This may be helpful for your purposes
Thanks, but, no, not really.

That seems to deal with a widget.

I am refering to the ability of LC 9.6 + to import SVGs via
the import image menu item.

While the import image menu item imports JPG, PNG and GIF image with their colour intect,
importing SVGs ends up with either a greyscale image of an image with the colour badly
compromised.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing SVG images

Post by richmond62 » Mon Apr 17, 2023 11:45 am

The gradient is imported exactly as it should be as far as I can see (when using Import Image locally with the supplied svg file).
NOT with 9.6.3 on MacOS 13.4 beta something.

I am at work, so merrily cranking up my 'steam-driven' Toshiba 32-bit laptop running 9.6.3 on Xubuntu as my
iMac here, running MacOS 10.7.5 gets stuck at LC 8.1.10.
Last edited by richmond62 on Mon Apr 17, 2023 11:47 am, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Importing SVG images

Post by bn » Mon Apr 17, 2023 11:46 am

richmond62 wrote:
Mon Apr 17, 2023 7:35 am
If an SVG image is imported via the 'import image' menu item any colours
get either lost or distorted:
I think that svgImport supports only a subset of SVG.

However it can perfectly import this:

Circle05-Orange3.svg.zip
(923 Bytes) Downloaded 147 times

This is the content of the svg above.

Code: Select all

<?xml version="1.0"?>
<svg viewBox="0 0 150 150">
<circle fill="#EDEDED" cx="72.592" cy="70.827" r="65.697"/>
<linearGradient id="XMLID_4_" gradientUnits="userSpaceOnUse" x1="20.9092" y1="14.6113" x2="128.0485" y2="131.1494">
<stop  offset="0" style="stop-color:#FFC10E"/>
<stop  offset="1" style="stop-color:#F16422"/>
</linearGradient>
<circle fill="url(#XMLID_4_)" cx="72.592" cy="70.827" r="63.159"/>
</svg>

look at the file in a text editor and see that it is extracted from the svg you posted. It is a bare bone svg file, without the embedded png you posted.

Disclaimer: I am not an SVG expert...

Kind regards
Bernd

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: Importing SVG images

Post by stam » Mon Apr 17, 2023 11:47 am

I should have checked before accepting that the report above was correct. Mark is of course entirely correct.

File menu -> import as control -> image works exactly as advertised. The gradient and color are preserved as per the original.

Tested with 9.6.9 on MacOS 13.2.1.

I don't have 9.6.3 installed any more and am not about to download to check, but not sure anything would have changed on that front...

=======
EDIT: Might there be something particular with your xubuntu installation?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing SVG images

Post by richmond62 » Mon Apr 17, 2023 11:52 am

So, to my 'steam-driven' Toshiba 32-bit laptop running 9.6.3:
-
Screenshot_2023-04-17_13-51-05.png
-
I assume, Bernd, that by
bare bone svg file
you mean that I should NOT expect any colours . . .

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Importing SVG images

Post by bn » Mon Apr 17, 2023 12:07 pm

richmond62 wrote:
Mon Apr 17, 2023 11:52 am
I assume, Bernd, that by
bare bone svg file
you mean that I should NOT expect any colours . . .
No, you should expect colors.

But I can confirm that neither Richmonds original svg with embedded png nor my "bare bone svg" import correctly using LC 9.6.3.
But they both import correctly using LC 9.6.9.

And if I remember correctly Mark Waddingham did some work in drawings.library especially regarding gradients. (that is the library used to import SVGs as image)
That might explain the difference between the LC versions because Richmond's example relies on gradients.

Kind regards
Bernd

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: Importing SVG images

Post by stam » Mon Apr 17, 2023 12:10 pm

Thanks for confirming Bernd...
Out of curiosity, would importing the SVG as text and running drawSVGCompile or some such get around this issue on 9.6.3?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Importing SVG images

Post by bn » Mon Apr 17, 2023 12:18 pm

stam wrote:
Mon Apr 17, 2023 12:10 pm
Thanks for confirming Bernd...
Out of curiosity, would importing the SVG as text and running drawSVGCompile or some such get around this issue on 9.6.3?
I do not think so because the version of drawing library used in 9.6.3 is 0.0.0 and the version of drawing library used in 9.6.9 is 1.0.0.

This leads me to belivieve that it is the version of drawing library that makes the difference.

Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing SVG images

Post by richmond62 » Mon Apr 17, 2023 1:55 pm

AND, as far as I recall, the SVG library is open source, so freely available.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Importing SVG images

Post by bn » Mon Apr 17, 2023 2:24 pm

richmond62 wrote:
Mon Apr 17, 2023 1:55 pm
AND, as far as I recall, the SVG library is open source, so freely available.
Library "drawing.livecodescript" in LC version 9.6.9 has this Copyright notice.
/* Copyright (C) 2021 LiveCode Ltd.
* All rights reserved.
*
* LiveCode Ltd. grants you a non-exclusive limited license to use this file,
* with or without modification, with the LiveCode product and in standalones
* built using the LiveCode product.
*
* Redistribution in source form, with or without modification, is permitted
* to other licensees of the LiveCode product provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * The name LiveCode Ltd. may not be used to endorse or promote products
* derived from this software without specific prior written permission.
Kind regards
Bernd
Last edited by bn on Mon Apr 17, 2023 2:26 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing SVG images

Post by richmond62 » Mon Apr 17, 2023 2:26 pm

Thank you for that clarification.

The question is, surely, whether 'licensees' includes users of the Open Source version and any derivatives of that.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Importing SVG images

Post by richmond62 » Tue Apr 18, 2023 10:28 am

"In a universe far, far way . . ."

Someone has proven that by swapping the drawing.livecodescript files from LC 9.6.9 into
LC 9.6.3 it is possible to import SVGs with gradients without any colour loss or distortion:
-
gradientLC.png
-
Of course 'Chewbacca' wonders if the laws that hold in "a universe far, far away" re playing "swoppsies"
are legal in our universe?

AND is reluctant to send his modded LC 9.6.3 community via a drone to our universe until that has been clarified.

Post Reply