首页/Home PHP Tutorial (教程) Create Button With ImageMagick In PHP

Create Button With ImageMagick In PHP

PrintE-mail
Tuesday, 30 June 2009 00:57  

This example will create a round cornered button. And you need to make sure that ImageMagic is installed.

 <?php
/* Create a new Imagick object */
$im = new Imagick();

/* Create empty canvas */
$im->newImage200200"white""png" );

/* Create the object used to draw */
$draw = new ImagickDraw();

/* Set the button color.
   Changing this value changes the color of the button */
$draw->setFillColor"#4096EE" );

/* Create a rectangle */
$draw->rectangle0017040 );

/* Fill color */
$draw->setFillColor"white" );

/* Semi-opaque fill */
$draw->setFillAlpha0.5 );

/* The font used for text */
$draw->setFont"./Vera.ttf" );

/* This is the alpha value used to annotate */
$draw->setFillAlpha0.17 );

/* Draw a curve on the button with 17% opaque fill */
$draw->bezier( array(
                array( 
"x" => "y" => ),
                array( 
"x" => 85"y" => 24 ),
                array( 
"x" => 170"y" => ),
               ) );

/* Render all pending operations on the image */
$im->drawImage$draw );

/* Set fill to fully opaque */
$draw->setFillAlpha);

/* Set the font size to 30 */
$draw->setFontSize25 );

/* The text on the */
$draw->setFillColor"white" );

/* Annotate the text */
$im->annotateImage$draw38280"Submit" );

/* Trim extra area out of the image */
$im->trimImage);

/* Add round corners */
$im->roundCorners4);

/* Clone the current object */
$shadow $im->clone();

/* Set the image background color to black (shadow color) */
$shadow->setImageBackgroundColor( new ImagickPixel('black') );

/* Create the shadow */
$shadow->shadowImage4011);

/* Add the original image above */
$shadow->compositeImage$imImagick::COMPOSITE_OVER0);

/* Output the image */
header"Content-Type: image/png" );

echo 
$shadow;
?>

The effect is as follows:

Imagick Button

And it's easy to change the font, color and size to fit your need.

 

回复

留个脚印儿吧.


回复