Here is an example of how to create a polaroid style effect on an image. This effect is available if you have compile Imagick against ImageMagick 6.2.8 or newer:
PHP:
-
<?php
-
-
/* Create the object and create the image */
-
$im = new Imagick( 'chev7_orig.png' );
-
-
/* Create a new ImagickDraw object
-
This is used to set polaroid properties */
-
$draw = new ImagickDraw();
-
-
/* Set the fill color to light blue */
-
$draw->setFillColor( new ImagickPixel( 'light blue' ) );
-
-
/* Create the polaroid image */
-
$im->polaroidImage( $draw, 20 );
-
-
/* Output */
-
echo $im;
-
-
?>
Here is the original image:

And here is the image with the polaroid effect:

#1 by John Kain on October 25, 2007 - 10:33 am
Quote
Really cool trick using php to modify images.
#2 by Tilli on January 30, 2008 - 5:48 pm
Quote
I have a problem, when i make a polaroid image, the background is black.
Where can i chance it to white or transparent?
#3 by Mikko Koppanen on January 30, 2008 - 5:51 pm
Quote
Tilli,
Is it a JPEG image?
#4 by Daniel Frechette on February 12, 2008 - 9:10 pm
Quote
I noticed that the polaroid image is slightly blurred compared to the original image. Is this a side effect of using the polaroid effect?
Thank you.
#5 by Daniel Frechette on February 19, 2008 - 2:26 am
Quote
Before I proceed to install ImageMagick on my server, I would like to know if applying transformations such as this one will affect the resulting image quality?
Thank you,
Daniel
#6 by Mikko Koppanen on February 19, 2008 - 11:07 pm
Quote
Daniel,
of course transformations have some effect on the image quality. Should be tolerable with good quality images.
#7 by fedmich on May 27, 2008 - 10:49 am
Quote
I need the same functionality but using Php GD only, anyone knows something about this… I know instant.js but I cant use it bcoz its a bit slow on my server.
Thanks in advance
#8 by Nico on August 24, 2008 - 7:30 pm
Quote
Hi Mikko,
I’ve same question as Tilli. I’ve got a polaroid image with black background. The setFillColor-command seems to have not effect…and yes, it is an jpeg image, with png all is fine. How can I make the background transparent? Second question: is there any possibility to change the border color of the polaroid?
Thanks…
#9 by Nico on August 24, 2008 - 10:47 pm
Quote
Ok, I’ve tried to change image format to png, so the background is transparency in Firefox (border color is also solved), but IE 6 looks terrible, I’ve included a png-patch for IE, and it seems to work with all png files except the polaroid pictures, which are created on the fly. When I add polaroid-look to a picture and save it to file, then IE shows it with transparency background (cause of the patch), but when the polaroid is only added on the fly, then IE doesn’t fix it!?
#10 by Nico on August 24, 2008 - 11:46 pm
Quote
One more thing. Is there something wrong or is it true, that a picture with polaroid-look and transparency background saved as png image is as 3 times bigger than jpeg file? setImageCompression doesn’t have effect to the png file and jpeg file with a quality of 100 is only a third of the png file!?
#11 by Benjamin on November 23, 2008 - 6:07 pm
Quote
That’s because PNG is lossless, Nico, so it will end up being quite a bit larger than the JPEG which has thrown away data to save that space (even at 100%) although there is a Lossless option some programs let you use on JPEGs which I can imagine would give you a size roughly the same as the PNG.
#12 by khurram shehzad on February 11, 2009 - 9:30 am
Quote
Hi,
Kindly can you tell me where to download all the following classes Imagick,ImagickDraw.
Regards,
Khurram Shehzad
#13 by Mikko Koppanen on February 11, 2009 - 12:58 pm
Quote
@khurram
Those classes are a part of the imagick extension.
#14 by loranger on April 24, 2009 - 4:43 pm
Quote
Thanks for sharing all this
I was trying to change the color of the polaroid border but failed.
Is there a way to do this or the polaroid method is a kind of bundle which cannot be modified ?
#15 by Mikko Koppanen on May 2, 2009 - 2:05 am
Quote
@loranger,
I think you change the border color, just can’t remember which method changes it
#16 by loranger on May 4, 2009 - 3:41 pm
Quote
I just dug a little bit further and found the methods you may talk about. They’re obvious :
// Set the border color used for the polaroid border
$im->setImageBorderColor( new ImagickPixel( ‘cornsilk’ ) );
// Set the background color used for the drop shadow
$im->setImageBackgroundColor( new ImagickPixel( ‘black’ ) );
#17 by Vinny on September 13, 2009 - 11:59 pm
Quote
How do i add text to the bottom of the polaroid
#18 by Vinny on September 14, 2009 - 12:59 am
Quote
oh and is it possible to use an external image in Imagick, e.g. From Youtube, http://img.youtube.com/vi/g_txF7iETX0/0.jpg
#19 by anderson freitas on January 14, 2010 - 6:16 am
Quote
Effect Polaroid-Controls ImagickMagick-LINUX
simple commnad line! hehehe! shell konsole konqueror
supertux@superlinux:~$
convert virginia.png -font Candice -pointsize 20 \
-bordercolor Snow -background black -fill dodgerblue -stroke navy \
-gravity center -set caption “ImagickMagick Convert Effect Polaroid-Controls by Big LINUX 4.2\!” -polaroid 10 \
poloroid_controls.png
link image:
http://www.4shared.com/file/196362089/add9e76b/Virginia_Model_Effect_Polaroid.html
#20 by Martijn Sandbergen on January 28, 2010 - 12:37 pm
Quote
Dont forget that the polaroid function changes the proportions of your image canvas, so you might get unexpected results if you don’t resize it back.
Also, for websites, you might want to have a random angle for each uploaded image.
The resulting script would then be something like this:
/* set your preferences
$filename = ‘chev7_orig.png’;
$bordercolor = ‘snow’;
$shadowcolor = ‘black’;
$minangle = -15;
$maxangle = 15;
/* Create the object and create the image */
$im = new Imagick( $filename );
/* Set the image format to png */
$im->setImageFormat(“png”);
/* Set the border and shadow color */
$im->setImageBorderColor( new ImagickPixel( $bordercolor ) );
$im->setImageBackgroundColor( new ImagickPixel( $shadowcolor ) );
/* Save the original dimensions */
$w = $im->getImageWidth();
$h = $im->getImageHeight();
/* Create the polaroid image. Not assigning ImagickDraw to a variable saves memory. mt_rand() is 4 times faster than rand() */
$im->polaroidImage( new ImagickDraw(), mt_rand( $minangle, $maxangle ) );
/* Resize back to original dimensions */
$im->thumbnailImage( $w, $h, true );
/* Output */
header( “Content-Type: image/”.$im->getImageFormat() );
echo $im;