RESOLVED - Does Imagick Support Radial Gradients ?

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.
Post Reply
nkline

RESOLVED - Does Imagick Support Radial Gradients ?

Post by nkline »

Hi,

PROBLEM
When using Imagick::newPseudoImage to create a radial gradient, this error appears in the Apache HTTP error log and the radial gradient is not created:

PHP Fatal error: Uncaught exception 'ImagickException' with message 'Unable to create new pseudo image: radial-gradient:#FF0000-#FFFFFF' in /var/www/html/energy/scripts/rg.php:6\nStack trace:\n#0 /var/www/html/energy/scripts/rg.php(6): Imagick->newpseudoimage(150,150, 'radial-gradient...')\n#1 {main}\n thrown in /var/www/html/energy/scripts/rg.php on line 6


RESEARCH
The documentation at http://us.php.net/manual/en/function.im ... oimage.php is lacking but according to http://www.imagemagick.org/script/formats.php (search for "radial"):
RADIAL_GRADIENT...Gradual radial passing from one shade to another...Returns a rendered radial gradient image using the specified image size. Specify the desired shading as part of the filename (e.g. radial-gradient:red-blue or radial-gradient:#F00-#00F).
I've tried using "RADIAL_GRADIENT" instead of "radial-gradient" and every other combination I could think of. Utimately, I would like to feed Imagick::newPseudoImage RGB values instead of hex and save the created images to disk.


My PHP script

Code: Select all

<?php
      // Create a new imagick object.
      $image = new Imagick();

      // A new image with radial gradient fading from red to white, 150 by 150 pixels.
      $image->newPseudoImage(150,150,'radial-gradient:#FF0000-#FFFFFF');

      // Set the image format to PNG.
      $image->setImageFormat('png');

      // Output the image.
      header("Content-Type: image/png");
      echo $image;
?>

My Environment
imagick 3.0.1RC1
ImageMagick 6.2.8.0
PHP 5.2.14
RedHat Enterprise Linux 5.5


Thank you!
Last edited by nkline on 2010-08-24T11:24:26-07:00, edited 1 time in total.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Does Imagick Support Radial Gradients ?

Post by el_supremo »

Instead of newpseudoimage try this:

Code: Select all

$image->setSize(150,150);
$image->readImage('radial-gradient:#FF0000-#FFFFFF');
Pete
nkline

Re: Does Imagick Support Radial Gradients ?

Post by nkline »

Thank you for the code suggestion and quick reply. Unfortunately, a fatal error is still produced:

PHP Script

Code: Select all

<?php
        // Create a new imagick object.
        $image = new Imagick();

        // An alternative to newPseudoImage.
        $image->setSize(150,150);
        $image->readImage('radial-gradient:#FF0000-#FFFFFF');

        // Set the image format to PNG.
        $image->setImageFormat('png');

        // Output the image.
        header("Content-Type: image/png");
        echo $image;
?>

Apache HTTP error_log
PHP Fatal error: Uncaught exception 'ImagickException' with message 'Unable to read the file: radial-gradient:#FF0000-#FFFFFF' in /var/www/html/energy/scripts/rg.php:10\nStack trace:\n#0 /var/www/html/energy/scripts/rg.php(10): Imagick->readimage('radial-gradient...')\n#1 {main}\n thrown in /var/www/html/energy/scripts/rg.php on line 10
Unsure if this is related
(process:6353): libgnomevfs-WARNING **: Unable to create ~/.gnome2 directory: Permission denied

I'm open to other recommendations. Maybe try upgrading ImageMagick (installed version = ImageMagick 6.2.8.0).

Thanks :-)
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Does Imagick Support Radial Gradients ?

Post by el_supremo »

Radial gradients were added in version 6.4.4-1 so you need to upgrade your version.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
DJ Mike
Posts: 33
Joined: 2010-06-29T19:07:53-07:00
Authentication code: 8675308

Re: RESOLVED - Does Imagick Support Radial Gradients ?

Post by DJ Mike »

That was new to me. Here is how it works:

Code: Select all

<?php
/* new imagick object */
$image = new Imagick();
/* a new pseudoimage with gradient */
$image->newPseudoImage( 100, 100, "radial-gradient:red-blue" );
/* set the image format to png */
$image->setImageFormat("png");
/* output to browser */
header( "Content-Type: image/png" );
echo $image;
?> 
And here is what it looks like
Image

Imagick::newPseudoImage
http://eclecticdjs.com/mike/tutorials/p ... php#radial
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
Post Reply