Skip to content

Instantly share code, notes, and snippets.

@benthebear
Created January 22, 2013 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benthebear/4592840 to your computer and use it in GitHub Desktop.
Save benthebear/4592840 to your computer and use it in GitHub Desktop.
<?php
$dir = scandir("./images");
unset($dir[0]);
unset($dir[1]);
$file = "images/".$dir[rand(2, count($dir))];
header("Content-type: image/jpg");
$source = imagecreatefrompng($file);
$size = getimagesize($file);
$width = $size[0];
$height = $size[1];
$x = floor($width - 200) / 2;
$y = floor($height - 100) / 2;
$target = imagecreatefromjpeg('teaser.jpg');
imagecopyresized($target, $source, 0, 0, $x, $y, 1078, 539, 200, 100);
imagejpeg($target);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment