![]() |
|
My Dynamic Sig - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: PHP (https://sinister.ly/Forum-PHP) +--- Thread: My Dynamic Sig (/Thread-My-Dynamic-Sig) |
My Dynamic Sig - slbmeh - 07-06-2011 I really love ImageMagick... but it's not really documented for PHP. You really just have to learn it by reading the class reflections and experimenting. This code is not optimal because I really only have a narrow self taught understanding of ImageMagick. This code demonstrates how to create an image with gradient background, push an existing image as a foreground fill, manipulate font attributes, write to the image, clone an image, set opacity, and how to push a watermark over an image, and output it to the browser. I used my sig as an example because I really needed a sig, and I was able to demonstrate majority of the core functionality of the Imagick classes that would be used in every day use all in a nice little package of my sig. The only thing really missing is how to thumbnail, and that can be done with a single line of code. If anyone has any questions as to how the Imagick class itself functions just let me know and I'll try to come up with an answer for you. I'm learning the functionality of this suite of classes by use of PHP Reflection. Okay, enough rambling, here's the code: Spoiler:PHP Code: <?php
/**
* Create a new image in memory space with a gradient background.
*/
$im = new Imagick();
$im->newPseudoImage(50,70, "gradient:black-red");
/**
* Create an image to be manipulated with the ImagickDraw class.
*/
$draw = new ImagickDraw();
/**
* Push the Pseudo Image defined by $im as the foreground fill color.
*/
$draw->pushPattern('gradient', 0, 0, 50, 60);
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 60, $im);
$draw->popPattern();
$draw->setFillPatternURL('#gradient');
/**
* Set the font face, font size, and coordinates for the annotation.
*/
$draw->setFont('RAZEROBLIQUE.ttf');
$draw->setFontSize(72);
$draw->annotation(20, 60, "slbmeh");
/**
* Set the font face, font size, and coordinates for the annotation.
*/
$draw->setFont('segoescb.ttf');
$draw->setFontSize(14);
$draw->annotation(40, 75, "Your IP address is " . $_SERVER['REMOTE_ADDR']); // This uses the PHP superglobal $_SERVER to grab the user's IP and append it to the string.
/**
* Create a new canvas to place our newly drawn image on.
*/
$canvas = new Imagick();
$canvas->newImage(330, 80, "white");
/**
* Place the drawn image on the canvas and add a 1x1px black border surrounded by a 5x5px white border.
*/
$canvas->drawImage($draw);
$canvas->borderImage('black', 1, 1);
$canvas->borderImage(new ImagickPixel("white"), 5, 5);
/**
* Convert the pseudo image to a real image format.
*/
$canvas->setImageFormat('png');
/**
* Clone the image defined in canvas and flip it for a reflection effect.
*/
$reflection = $canvas->clone();
$reflection->flipImage();
/**
* Create a new pseudo image with a transparent to black gradient to add a fade effect on top of the reflection.
*/
$gradient = new Imagick();
$gradient->newPseudoImage($reflection->getImageWidth() + 10, $reflection->getImageHeight() + 10, "gradient:transparent-black");
/**
* Push the gradient on top of the reflection and define a transparency.
*/
$reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0);
$reflection->setImageOpacity( 0.3 );
/**
* Create the final canvas for the two images to be drawn to.
*/
$final = new Imagick();
/**
* Define the width to allow for 20px side margins.
* Define the height to be twice the size to fit both images and add 30px to allow for 15px top and bottom margins.
*/
$width = $canvas->getImageWidth() + 40;
$height = ($canvas->getImageHeight() * 2) + 30;
$final->newImage($width, $height, new ImagickPixel("black"));
$final->setImageFormat("png");
/**
* Draw the initial image to the final image.
* Draw the reflection image to the final image with an offset in respect to the height of the initial image.
*/
$final->compositeImage($canvas, imagick::COMPOSITE_OVER, 20, 10);
$final->compositeImage($reflection, imagick::COMPOSITE_OVER, 20, $canvas->getImageHeight() + 10);
/**
* Define the header mime type for output and push the image out to the browser.
*/
header("Content-Type: image/png");
echo $final;
?>Edit: Any feedback is appreciated. RE: My Dynamic Sig - 1llusion - 07-27-2011 Thanks! gonna use it =) RE: My Dynamic Sig - Shining White - 08-02-2011 Can you please make some tut with it ?
RE: My Dynamic Sig - KaiT_AleX - 08-02-2011 Great code... I like it ! RE: My Dynamic Sig - slbmeh - 08-06-2011 (08-02-2011, 08:57 PM)Shining White Holmse Wrote: Can you please make some tut with it ? What exactly are you looking for as far as a tut? |