Creating 100 Megan Foxii

April 12, 2010

A couple of people have asked me how I created the image of 100 Megan Foxii (100 images of Megan Fox superimposed).

It’s actually really simple, using PHP. In fact, it only took about 20 lines of code:


// Get list of all photos
$aImg = array_diff(scandir('./photos/'), array('.','..'));

// Create blank white canvas
$im    = imagecreatetruecolor(400, 600);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 400, 600, $white);

// Place each image on to canvas, re-sized
foreach ($aImg as $img_path)
    $filename = './photos/' . $img_path;
    $tmpIm    = imagecreatefromjpeg($filename);
    list($width, $height) = getimagesize($filename);
    $photoIm = imagecreatetruecolor(400, 600);
    imagecopyresized ($photoIm, $tmpIm, 0, 0, 0, 0, 400, 600, $width, $height);

    imagecopymerge($im, $photoIm, 0, 0, 0, 0, 400, 600, 3);

header('Content-type: image/jpeg');


Change the 400 (width) and 600 (height) in the code to whatever your output image size is; it just turns out that most of my images were around this size (it doesn’t matter if all of them are, as the script re-sizes the images).

You may also need to play around with the ‘3’ at the end of the imagecopymerge() function; it’ll need increasing a bit if you have less than 100 images, and decreasing if you use more than 100 images. Just play around and see what gives you the best effect (it defines the opacity of each image that is merged).

Leave a Reply