adaptiveResizeImage( 400,400 ); $canvas = new Imagick(); $canvas->newImage( 500, 500, new ImagickPixel( "transparent" ) ); $canvas->setImageFormat( "png" ); /* paths to the images */ //$paths = array( "chev7.jpg", "myfrog.jpg", "strawberry.jpg", "Image32.jpg" ); $paths = array(); $d = dir('.'); while ($file = $d->read()) { if (preg_match('!^p.*\.jpg$!', $file)) $paths[] = $file; } $d->close(); shuffle($paths); $paths = array_slice($paths, 0, 5); /* Create an empty ImagickDraw object (Use the defaults for the polaroid) */ $bg = new ImagickDraw(); /* Create a few random images */ $images = new Imagick( $paths ); /* Loop trough images, overlay on canvas and remove the image */ foreach ( $images as $key => $image ) { /* Thumbnail to 100x width and set background to black. It looks like an drop-in shadow */ $image->thumbnailImage( mt_rand(100, 200), null ); $image->setImageBackgroundColor( new ImagickPixel( "black" ) ); /* Use a random angle */ $angle = mt_rand( -45, 45 ); if ( mt_rand( 1, 2 ) % 2 === 0 ) { $angle = $angle * -1; } /* Create the polaroid */ $image->polaroidImage( $bg, $angle ); /* Composite the polaroid over the canvas */ /* Composite to a random location */ $canvas->compositeImage( $image, Imagick::COMPOSITE_OVER, mt_rand( 10, 150 ), mt_rand( 10, 150 ) ); /* Free some resources */ $image->removeImage(); } $canvas->trimImage( 0 ); /* Display the image */ header( "Content-Type: image/png" ); echo $canvas; ?>