Create Text Image with Gradient color Applying StrokeWidth

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
arun
Posts: 1
Joined: 2016-06-13T07:55:25-07:00
Authentication code: 1151

Create Text Image with Gradient color Applying StrokeWidth

Post by arun »

Hi Everybody,

Im Working on Creating Text Image with gradient colors with Strokewidth Applied to the Text(i.e.as per #Image Model), but able to success it for certain level, but when apply the Strokewidth & StrokeColor it takes only The Color of gradient.png(gradient colored imaged) i have created it with imagick instance,& I'm merging the gradient.png & canvas.png(that contains the imagickDraw for Text "CAPTURE"), (i.e. My_output_Image). But the Final output i need was like #image Model & also i need the options the increase the quality of image.

#Image Model:
Image
#My_output_Image:
Image

This is my code :
------------------

Code: Select all

<?php
/* Create and save the gradiant */
$Imagick = new \Imagick();
$Imagick->newPseudoImage( 500, 100, "gradient:#83D6FC-#0088FF" );
$Imagick->setImageFormat( 'png' );
$Imagick->writeImage("gradiant.png");

/* Create and save the canvas */
$im = new \Imagick();
$im->newPseudoImage( 500, 100, "null:" );
$im->setImageFormat( 'png' );
$im->writeImage("canvas.png");

/* Add the text to the canvas ( Make the mask )*/
$im = new \Imagick( "canvas.png" ); 
$draw = new ImagickDraw();
$draw->setFont('Capture_it.ttf');
$draw->setFontSize( 90 ); 

$draw->setStrokeColor('#000000');
$draw->setStrokeWidth(2);	
$draw->setFillColor( new \ImagickPixel("white"));

// Set gravity to the center.
$draw->setGravity( Imagick::GRAVITY_CENTER );
// Write the text on the image 
$im->annotateImage( $draw, 0, 0, 0, "CAPTURE" );

/* Final image */
$canvas = new \Imagick( "gradiant.png" ); 
$canvas->compositeImage($im, \Imagick::COMPOSITE_COPYOPACITY, 0, 0.75);
$canvas->compositeImage( $im, imagick::COMPOSITE_DSTIN, 0, 0 );
$canvas->setImageFormat( 'png' );
$canvas->writeImage("final.png");

header("Content-Type: image/png");
echo $canvas;
?>
Thank You,
Any Help Appreciated. Plz Correct Me If i have Made Making any Mistakes...
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Create Text Image with Gradient color Applying StrokeWidth

Post by Bonzo »

This is some old code on mine that works; although may or may not work with your version of Imagick.

Code: Select all

/* Create and save the gradiant */
$Imagick = new Imagick();
$Imagick->newPseudoImage( 500, 100, "gradient:red-orange" );
$Imagick->setImageFormat( 'png' );
$Imagick->writeImage("gradiant.png");

/* Create and save the canvas */
$im = new Imagick();
$im->newPseudoImage( 500, 100, "null:" );
$im->setImageFormat( 'png' );
$im->writeImage("canvas.png");

/* Add the text to the canvas ( Make the mask )*/
$im = new Imagick( "canvas.png" ); 
$draw = new ImagickDraw();
$draw->setFontSize( 90 ); 
$draw->setFillColor( new ImagickPixel("black"));

// Set gravity to the center.
$draw->setGravity( Imagick::GRAVITY_CENTER ); 
 
// Write the text on the image 
$im->annotateImage( $draw, 0, 0, 0, "Anthony" );

/* Final image */
$canvas = new Imagick( "gradiant.png" ); 
$canvas->compositeImage( $im, imagick::COMPOSITE_DSTIN, 0, 0 );
$canvas->setImageFormat( 'png' );
$canvas->writeImage("final.png");

unlink("canvas.png");
unlink("gradiant.png");
?>
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Create Text Image with Gradient color Applying StrokeWidth

Post by Bonzo »

Just tried my code to make sure it works but I get a black background; probably something to do with transparency. But as I say a lot depends on the Imagick version you have; this worked a year or so ago but does not now. I assume the hosts have updated the version on my server but you may be lucky.
Post Reply