Jump to content

Reflection with Imagick


Recommended Posts

I didn't write this. I had it saved from a few years back and came across it last night and thought some of you might like the effect. Takes an image like this:

 

 

and reflects it like this:

 

 

<?php
# Read the image
$im = new Imagick("../../images/heliohost.png");

# Clone the image and flip it
$reflection = $im->clone();
$reflection->flipImage();

# Create gradient. It will be overlayd on the reflection
$gradient = new Imagick();

# Gradient needs to be large enough for the image 
$gradient->newPseudoImage($reflection->getImageWidth(), $reflection->getImageHeight(), "gradient:transparent-black");

# 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.3 );

# Create an empty canvas 
$canvas = new Imagick();

# Canvas needs to be large enough to hold the both images 
$width = $im->getImageWidth();
$height = ($im->getImageHeight() * 2);
$canvas->newImage($width, $height, new ImagickPixel("black"));
$canvas->setImageFormat("png");

# Composite the original image and the reflection on the canvas 
$canvas->compositeImage($im, imagick::COMPOSITE_OVER, 0, 0);
$canvas->compositeImage($reflection, imagick::COMPOSITE_OVER, 0, $im->getImageHeight());

# uncomment to write image to your directory
# $canvas->writeimage("reflected.png");

# output image
header("Content-Type: image/png");
echo $canvas;
?>

 

Link to comment
Share on other sites

I didn't write this. I had it saved from a few years back and came across it last night and thought some of you might like the effect. Takes an image like this:

 

 

and reflects it like this:

 

That's really cool. Much easier than adding reflections in the gimp or photoshop or whatever like I have always done in the past. I haven't actually tried it yet, but what is the deal with the mouse cursor? Just happened to have it sitting there when the screen shot was taken or something?

Link to comment
Share on other sites

Those are the actual png images the script creates and not screen shots. Maybe you've mistaken the arrow in the image for the curser?

 

btw, if your interested in imaging, check out what we can do with the Imagick Class.

 

http://byrondallas.heliohost.org/php/imagi...all-methods.php

 

If you'll click onto the link that says DJ Mike's examples, you'll find more examples there than at php.net.

 

 

Link to comment
Share on other sites

Those are the actual png images the script creates and not screen shots. Maybe you've mistaken the arrow in the image for the curser?

Yeah, there is an arrow in the background pointed towards the top right, but am I the only one that sees the mouse pointer arrow pointed straight at Tux's chest? :blink: That's why I asked if it was a screenshot. I just figured you took a screenshot to make the original image rather than saving the image.

btw, if your interested in imaging, check out what we can do with the Imagick Class.

 

http://byrondallas.heliohost.org/php/imagi...all-methods.php

 

If you'll click onto the link that says DJ Mike's examples, you'll find more examples there than at php.net.

Yep, very good information in there. I followed that link back when you posted the rainbow swirly text script http://www.helionet.org/index/index.php?showtopic=9136 which is also very cool.

Link to comment
Share on other sites

Guest Geoff
Yeah, there is an arrow in the background pointed towards the top right, but am I the only one that sees the mouse pointer arrow pointed straight at Tux's chest? That's why I asked if it was a screenshot. I just figured you took a screenshot to make the original image rather than saving the image.

 

Someone created that logo for us, but we didn't use it because it did not look as good as our current logo.

Link to comment
Share on other sites

Yeah, there is an arrow in the background pointed towards the top right, but am I the only one that sees the mouse pointer arrow pointed straight at Tux's chest? That's why I asked if it was a screenshot. I just figured you took a screenshot to make the original image rather than saving the image.

Someone created that logo for us, but we didn't use it because it did not look as good as our current logo.

Ok, I guess that explains it. I like the logos that are in use better than this one too. -_-

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...