Basic question - PHP usage of SVG files

This is a discussion on Basic question - PHP usage of SVG files within the PHP General forums, part of the PHP Programming Forums category; PHP list, I have some images that are in SVG format. What I want to do with them is manipulate ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-21-2007
Dave M G
 
Posts: n/a
Default Basic question - PHP usage of SVG files

PHP list,

I have some images that are in SVG format. What I want to do with them
is manipulate them by resizing and overlaying one on top of the other.

I do this frequently with PNG images, and I could first convert these
images to PNG before manipulating them in PHP.

However, I'd like to preserve line quality by keeping them as SVG until
the last moment.

I can't see on the online documentation if SVG is supported and if it
requires different commands than raster image formats.

What is the support for SVG in PHP, and where is the online
documentation for it?

Thank you for your help.

--
Dave M G
Reply With Quote
  #2 (permalink)  
Old 11-21-2007
Casey
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files

On Nov 20, 2007 7:24 PM, Dave M G <martin@autotelic.com> wrote:
> PHP list,
>
> I have some images that are in SVG format. What I want to do with them
> is manipulate them by resizing and overlaying one on top of the other.
>
> I do this frequently with PNG images, and I could first convert these
> images to PNG before manipulating them in PHP.
>
> However, I'd like to preserve line quality by keeping them as SVG until
> the last moment.
>
> I can't see on the online documentation if SVG is supported and if it
> requires different commands than raster image formats.
>
> What is the support for SVG in PHP, and where is the online
> documentation for it?
>
> Thank you for your help.
>
> --
> Dave M G
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


There is no SVG support in PHP, as far as I know. However, since SVG's
are XML's, you could extract the contents of <svg> in both files and
merge them together.

-Casey
Reply With Quote
  #3 (permalink)  
Old 11-21-2007
Dave M G
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files [SOLVED]

Casey,

> There is no SVG support in PHP, as far as I know.


Thank you. That clears things up. I'll just go with PNGs then.

--
Dave M G
Reply With Quote
  #4 (permalink)  
Old 11-21-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files [SOLVED]

On Wednesday 21 November 2007, Dave M G wrote:
> Casey,
>
> > There is no SVG support in PHP, as far as I know.

>
> Thank you. That clears things up. I'll just go with PNGs then.


I think you missed the point. SVG is just text. It's XML. You can
manipulate it with SimpleXML or the DOM API functions just as you would any
other XML file. It's been a while since I worked with SVG, but I believe you
can resize an image just by changing an attribute or two. There's no need
for SVG support per se, as SimpleXML provides all you need anyway. That's
the advantage of XML. :-)

--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
  #5 (permalink)  
Old 11-22-2007
Dave M G
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files

Larry,

Thank you for responding.

> I think you missed the point. SVG is just text. ... There's no need
> for SVG support per se, as SimpleXML provides all you need anyway.


I did miss the point - thanks for setting me straight.

However, I'm still unsure about using SVGs. On the one hand, what I'm
using as source files are originally in SVG format and I want to be able
to dynamically resize and scale them without loss of clarity.

But, after they have been resized and scaled, then I think I need to
send the resulting image to the browser in some raster image format.
Indications are that SVG support on browsers is still not as uniform as
PNG or other raster graphics formats.

At that last step, assuming that I have manipulated the images to my
satisfaction with SimpleXML, can I then output the result in PNG or JPG
with PHP?

I'm not so sure this can be done. The tricky part is that I am building
PHP scripts that could be deployed on servers with different PHP
settings, so I'm not confident that I can rely on PEAR or ImageMagick
functions being present. Are they standard on PHP > 5?

Forgive me if my questions are clueless to the point of making the
questions unclear.

--
Dave M G
Reply With Quote
  #6 (permalink)  
Old 11-22-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files

On Wednesday 21 November 2007, Dave M G wrote:
> Larry,
>
> Thank you for responding.
>
> > I think you missed the point. SVG is just text. ... There's no need
> > for SVG support per se, as SimpleXML provides all you need anyway.

>
> I did miss the point - thanks for setting me straight.
>
> However, I'm still unsure about using SVGs. On the one hand, what I'm
> using as source files are originally in SVG format and I want to be able
> to dynamically resize and scale them without loss of clarity.


That sounds like an excellent reason to use SVG for your image manipulation.

> But, after they have been resized and scaled, then I think I need to
> send the resulting image to the browser in some raster image format.
> Indications are that SVG support on browsers is still not as uniform as
> PNG or other raster graphics formats.


Yeah, Firefox is the only browser I know of with native SVG support worth a
damn. Konqueror keeps talking about it but I don't know if it's any good
yet. Not sure about Opera or Safari. IE requires a plugin from Adobe, which
the last time I was playing with it (which has been a while, but there were
no signs of plans to improve it at the time) was OK, but not great and
embedded a la flash in a fixed, immutable box.

> At that last step, assuming that I have manipulated the images to my
> satisfaction with SimpleXML, can I then output the result in PNG or JPG
> with PHP?


With native PHP, I don't believe so. However, I know that there are assorted
command line tools and Java tools to do so. I naturally can't think of them
off the top of my head, but I know they exist. You could exec() out to them
to cache the rasterized combined image to disk and then serve that.

I don't know off hand if there's a PECL module or some user-space PHP code to
do that. It's worth spending 10 min Googling it, though.

> I'm not so sure this can be done. The tricky part is that I am building
> PHP scripts that could be deployed on servers with different PHP
> settings, so I'm not confident that I can rely on PEAR or ImageMagick
> functions being present. Are they standard on PHP > 5?


Now that could be a problem. You'd have to find either some PHP user-space
library or a CLI C library that you could bundle with the app. I'm fairly
certain nothing like that is in stock PHP 5. As for finding a good such
library, as I said Google would know better than I. (Or maybe I should say
Yahoo, since they use PHP. <g>)

> Forgive me if my questions are clueless to the point of making the
> questions unclear.


They make a lot more sense now, actually. :-)


--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
  #7 (permalink)  
Old 11-24-2007
Dave M G
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files [SOLVED]

Larry,

Thanks for your advice.

With the XML editor available within PHP, I've made a small script that
can extract the point data inside an SVG file, and store them as an
array of points.

That array can then be used to draw and fill shapes in a PNG image. And
since they are stored as an array, I can do a little math on them to
manipulate their scale and whatnot.

The interpolation between points gets lost with this method, but in this
case, I can get by with straight lines.

Thanks for helping me to see the value in using PHP's XML functions.

--
Dave M G
Reply With Quote
  #8 (permalink)  
Old 11-24-2007
tedd
 
Posts: n/a
Default Re: [PHP] Basic question - PHP usage of SVG files [SOLVED]

At 1:14 PM +0900 11/24/07, Dave M G wrote:
>Larry,
>
>Thanks for your advice.
>
>With the XML editor available within PHP, I've made a small script
>that can extract the point data inside an SVG file, and store them
>as an array of points.
>
>That array can then be used to draw and fill shapes in a PNG image.
>And since they are stored as an array, I can do a little math on
>them to manipulate their scale and whatnot.
>
>The interpolation between points gets lost with this method, but in
>this case, I can get by with straight lines.
>
>Thanks for helping me to see the value in using PHP's XML functions.
>
>--
>Dave M G



Dave:

If you want to smooth those points out, you can do it with a bezier
or catmull spline.

The code for catmull spline can be found here:

http://brlcad.org/doxygen/d7/ddd/rt_...8c-source.html

I would love to see it translated into php.

I have a copy of bezier code in C -- contact me off-list for a copy.

Cheers,

tedd


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
Reply With Quote
  #9 (permalink)  
Old 11-24-2007
Al
 
Posts: n/a
Default Re: Basic question - PHP usage of SVG files

Imagemagick php extension http://www.php.net/manual/en/ref.imagick.php

Works great.

Dave M G wrote:
> PHP list,
>
> I have some images that are in SVG format. What I want to do with them
> is manipulate them by resizing and overlaying one on top of the other.
>
> I do this frequently with PNG images, and I could first convert these
> images to PNG before manipulating them in PHP.
>
> However, I'd like to preserve line quality by keeping them as SVG until
> the last moment.
>
> I can't see on the online documentation if SVG is supported and if it
> requires different commands than raster image formats.
>
> What is the support for SVG in PHP, and where is the online
> documentation for it?
>
> Thank you for your help.
>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:35 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0