readImageBlob(svg) crashing apache?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

readImageBlob(svg) crashing apache?

Post by charlie1234 »

My delegates: bzlib djvu fontconfig freetype gvc jpeg jng jp2 lcms lqr openexr png rsvg tiff x11 xml wmf zlib
My version: 6.6.7.10

If I attempt to $im->readImageBlob($svg) then I *was* getting:

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `/tmp/magick-IB2RqGfx' @ error/svg.c/ReadSVGImage/2831' in /var/www/apache2/svg/serve-layers.php:41 Stack trace: #0 /var/www/apache2/svg/serve-layers.php(41): Imagick->readimageblob('
I uninstalled IMagick (through PECL uninstall command) installed newer versions of libxml2, librsvg, libcroco, etc., and then re-installed ImageMagick from source (6.6.7.10) and re-installed IMagick. Now I am getting Error 324 (Empty Response) from my server. A quick glance into /var/log/apache2/error.log reveals Segmentation faults every time I attempt to load an SVG via readImageBlogb().:

Code: Select all

[notice] child pid 1592 exit signal Segmentation fault (11)
This has extended about as far as my knowledge of Linux / compiling / etc., has taken me. At this point I've no idea what to try... The same PHP script is working on my local virtual ubuntu machine to parse SVGs.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: readImageBlob(svg) crashing apache?

Post by anthony »

try using something less complicated than SVG first.

For example try a simple blob string "P2 2 2 2 2 1 1 0 ", which creates a 2x2 pixel grayscale image (PGM)
If that works but the SVG doesn't then you know readblob() is okay but the svg side isn't, and visa-versa.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

Thanks anthony. That works -- I get a 2x2 pixel black box. I used the following code:

Code: Select all

<?php
$im = new Imagick();
$im->readImageBlob('P2 2 2 2 2 1 1 0');
$im->setImageFormat('png');
header("Content-type: image/png");
print $im->getimageblob();
Do you have any suggestions on how I can continue testing?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: readImageBlob(svg) crashing apache?

Post by anthony »

So the problem is with SVG.

You now need to find out if Im is using MSVG or RSVG for svg handling.
http://www.imagemagick.org/Usage/draw/#svg

if it is RSVG, than you may have a library problem in that it is not finding the RSVG libraries.
I would be ALL logging errors and seeing what they say.
http://www.ict.griffith.edu.au/anthony/ ... /php.hints

Also checking error returns of the imagick function calls.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

Using RSVG, definitely. Here's the PHP error I see:
Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `/tmp/magick-Oz1tbLmc' @ error/svg.c/ReadSVGImage/2831' in /var/www/apache2/svg/serve-layers.php:40 Stack trace: #0 /var/www/apache2/svg/serve-layers.php(40): Imagick->readimageblob('
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: readImageBlob(svg) crashing apache?

Post by fmw42 »

charlie1234 wrote:Using RSVG, definitely. Here's the PHP error I see:
Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `/tmp/magick-Oz1tbLmc' @ error/svg.c/ReadSVGImage/2831' in /var/www/apache2/svg/serve-layers.php:40 Stack trace: #0 /var/www/apache2/svg/serve-layers.php(40): Imagick->readimageblob('

I was having a problem with RSVG in IM (command line) not rendering a simple example from http://www.w3.org/TR/SVG/shapes.html#RectElement

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Example rect01 - rectangle with sharp corners</desc>

<!-- Show outline of canvas using 'rect' element -->
<rect x="1" y="1" width="1198" height="398"
fill="none" stroke="blue" stroke-width="2"/>

<rect x="400" y="100" width="400" height="200"
fill="yellow" stroke="navy" stroke-width="10" />
</svg>

convert file.svg file.png

did not work. It did not do the fill colors correctly.

But

conver file.svg MVG:file.png

worked.

I was using

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.32.1)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (RSVG 2.32.1)

What version are you using? Can you render the above example correctly with your version?
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

Just tried to render that code in PHP -- I get a 324 error (empty response). Checking my error.log shows
child pid xxxx exit signal Segmentation fault (11)
I then saved that code into 'test.svg' and ran 'convert test.svg test.png' and got a beautiful yellow box with a 2px gray border as a PNG. So I guess this is IMagick and not ImageMagick that's troubling me?

Edit: I did not try MVG:... Should I even worry about that if the normal convert works on command line?
Edit++: I am using ImageMagick v 6.6.7, RSVG 2.34.0, LIBXML 2.2.7.3, iMagick 3.1.0.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: readImageBlob(svg) crashing apache?

Post by fmw42 »

Edit: I did not try MVG:... Should I even worry about that if the normal convert works on command line?
Edit++: I am using ImageMagick v 6.6.7, RSVG 2.34.0, LIBXML 2.2.7.3, iMagick 3.1.0.
Don't worry. It looks like your more current RSVG is working where my older version is not. I will have to try to upgrade and test again.

Thanks for checking that for me.
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

Righto. I will sit tight and see if anyone else has any suggestions.

The odd part about this for me is that I setup 2 Ubuntu servers with nearly identical setups and on 1 server this code works fine -- deployed it to production server and no-go. Everything was installed via apt-get or PECL (until the error, at which point I started compiling all of these from source).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: readImageBlob(svg) crashing apache?

Post by fmw42 »

Have you tried disabling openMP?
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

I have not. Does that require a recompile? If so, will a re- ./configure / make / make install with the --disable-openmp flag do it? Do I need to remove or uninstall anything first? I have not been until now but I see this as a good place to ask that question.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: readImageBlob(svg) crashing apache?

Post by fmw42 »

Does that require a recompile? If so, will a re- ./configure / make / make install with the --disable-openmp flag do it?
Yes. That is correct. Nothing further need be done as far as I know.

The --disable-openmp flag goes in your ./configure command.

See the search results at search.php?keywords=disable+openMP&term ... mit=Search

for examples when suggested to disable openMP
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: readImageBlob(svg) crashing apache?

Post by anthony »

I see two posibilities.

1/ the rsvg coder is not finding the rsvg library.

2/ one of the libraries was built with a different version than expected.

Note the IMagick is gettings old, and it may be a incompatibility with the fucntions between imagick and Imagemagick,

OR it could be a version incomapibility between imagemagick RSVG and the RSVG library.

That last is now likely as command line works.
The former is a posibility.

The first one however may be the problem.

Try running the command line version as an exec() call from PHP. If that works (check error reports) then the PHP environment is finding the right library. Otherwise looks like a PHP imagick to imagemagick incompatibility.
To work out that a stack trace would be the next step.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

The exec() worked but I couldn't get imagick to work within that virtual machine instance for the life of me. I destroyed the VM and built a new one and was able to get things working without problems. I don't know what the real issue was. Thank you very much for the help and info, hopefully something in this thread is useful to others in the future.
charlie1234
Posts: 16
Joined: 2011-07-27T21:24:03-07:00
Authentication code: 8675308

Re: readImageBlob(svg) crashing apache?

Post by charlie1234 »

I had to upgrade ImageMagick from 6.6.2 to a newer version, 6.7.x, so that some newer functions would work, and I'm getting this error again.

I'm now using ImageMagick version 6.7.4
Imagick version 3.0.1
Server is Litespeed 4.0.10.
PHP 5.3.8
ImageMagick is using RSVG. Compiled without OpenMP.

Here is some example code which causes segmentation fault:

Code: Select all

<?php
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->setFormat('svg');
$svg_blob = file_get_contents('another-butterfly.svg');
$im->readImageBlob($svg_blob);
$im->setImageFormat('png32');
header("Content-Type: image/png");
$im->getimageblob();
The SVG it's using:
another-butterfly.svg.zip
(10.66 KiB) Downloaded 1428 times
To quote Anthony, I wonder if this may be the problem:
Note the IMagick is gettings old, and it may be a incompatibility with the fucntions between imagick and Imagemagick,
Last edited by charlie1234 on 2012-01-27T11:56:02-07:00, edited 1 time in total.
Post Reply