02
Nov
0
Web 2.0 Mirrored Images
What it Does
Provides an easy way to create 'reflected' images.
Attached Files
Web 2.0 Reflections(3 KB)
Ever wanted to create the so-called 'web 2.0' mirrored images as you can see on http://www.dio5.com/portfolio/, without having to manually rotate and proces the image? Then this one is for you.
I attached a fully working zip-package, but let's run through some of the code nonetheless.
When it comes to images the Image and GD class are the ones we need to tackle. Create a file in your mysite/code/ folder called ImageDecorator.php and add in the next code:
Create another file called MyGD.php in the same folder:
The previous code may look a bit daunting but it's basically just taking the current picture and mirrors it, after which we do a crop on it so you can add in a width & height.
To get the Image Decorator working, we'll need to add this line to our _config.php file:
The interesting part is how you can use it in your templates: $ExampleImage.getMirroredImage(300,200) will give you a mirrored image with a width of 300px and height of 200px.
Combine this with some clever use of css and a png gradient and you will be able to achieve what I did on http://www.dio5.com/portfolio/.
For those of you wanting to test this out, I provided a simple zip-package which contains a folder called 'mirrors'. Just unzip this in your root SS-folder, do a dev/build/ and you'll have an 'Example Page'-type which allows you to set an image on which this effect is demonstrated. It basically contains this html-snippet:
With this css:
Here we are adding the mirrored image as a background image on the outer container div of the 'normal' image. On the inner container div we add a black to transparent png-gradient and position the whole thing with css.
You probably want to experiment with changing the png-overlay image size & color in the zip. For a reflection on white you'll need to replace it with a white to transparent one, instead of a black one.
Hope this little snippet inspired you to do great things! Do not hesitate to ask for help or improve this where possible.
Note: I'm not adding support for IE6 here.
About the Author
Name: Dieter Orens
Website: http://www.dio5.com/portfolio/
Dieter 'dio5' Orens is a freelance web designer and developer living in Belgium.
Comments (0)
No one has commented on this page yet.
RSS feed for comments on this page RSS feed for all comments