Page 1 of 1

How to create an image reflextion from an text image.

Posted: 2008-07-19T03:10:03-07:00
by bartje1974
Hi all,

First of al imagick is cool stuff! :D

I want to create an image with text.
That's simple. But i want to have a reflextion from that image.
Like "on the fly".
I can not find very much on goolge, so i hope that anyone can help here.
On php.net i found how to create a reflextion, but i want it from this code.

Code: Select all

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

/* Create new image. This will be used as fill pattern */
$im->newPseudoImage(50, 50, "gradient:red-black");

/* Create imagickdraw object */
$draw = new ImagickDraw();

/* Start a new pattern called "gradient" */
$draw->pushPattern('gradient', 0, 0, 50, 50);

/* Composite the gradient on the pattern */
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);

/* Close the pattern */
$draw->popPattern();

/* Use the pattern called "gradient" as the fill */
$draw->setFillPatternURL('#gradient');

$draw->setFont('./ExplosiveBold.ttf');
/* Set font size to 40 */
$draw->setFontSize(40);

/* Annotate some text */
$draw->annotation(5, 50, 'Hello World');

/* Create a new canvas object and a white image */
$canvas = new Imagick();
$canvas->newImage(350, 70, "white");

/* Draw the ImagickDraw on to the canvas */
$canvas->drawImage($draw);

/* 1px black border around the image */
$canvas->borderImage('black', 1, 1);

/* Set the format to PNG */
$canvas->setImageFormat('png');

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

From that output i want a reflextion.
How can i do that?
Sorry for my bad English, it's a long time i wrote in it.

Thanks for the help.

Re: How to create an image reflextion from an text image.

Posted: 2008-07-20T00:59:05-07:00
by bartje1974
Found the solution! 8)
This works fine.
The code:

Code: Select all

<?php

/* Create a new imagick object */
$im = new Imagick();

/* Create new image. This will be used as fill pattern */
$im->newPseudoImage(50, 50, "gradient:red-black");

/* Create imagickdraw object */
$draw = new ImagickDraw();

/* Start a new pattern called "gradient" */
$draw->pushPattern('gradient', 0, 0, 50, 50);

/* Composite the gradient on the pattern */
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);

/* Close the pattern */
$draw->popPattern();

/* Use the pattern called "gradient" as the fill */
$draw->setFillPatternURL('#gradient');

/* Setup the font */
$draw->setFont('./ExplosiveBold.ttf');

/* Set font size to 52 */
$draw->setFontSize(43);

/* Annotate some text */
$draw->annotation(5, 45, "Hello World!");

/* Create a new canvas object and a white image */
$canvas = new Imagick();
$canvas->newImage(450, 40, "white");

/* Draw the ImagickDraw on to the canvas */
$canvas->drawImage($draw);

$reflection = $canvas->clone();
$reflection->flipImage();
/* Create gradient. It will be overlayd on the reflection */
$gradient = new Imagick();

/* Gradient needs to be large enough for the image and the borders */
$gradient->newPseudoImage($reflection->getImageWidth() + 10, $reflection->getImageHeight() + 10, "gradient:transparent-white");

/* Composite the gradient on the reflection */
$reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0);

/* Add some opacity. Requires ImageMagick 6.2.9 or later */
$reflection->setImageOpacity( 0.2 );

$Result = new Imagick();


$width = $canvas->getImageWidth() + 40;
$height = ($canvas->getImageHeight() * 2) + 30;
$Result->newImage($width, $height, new ImagickPixel("white"));


/* Composite the original image and the reflection on the canvas */
$Result->compositeImage($canvas, imagick::COMPOSITE_OVER, 20, 10);
$Result->compositeImage($reflection, imagick::COMPOSITE_OVER, 20, $canvas->getImageHeight() + 10);


/* Set the format to PNG */
$Result->setImageFormat('png');

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