Skip to content

Instantly share code, notes, and snippets.

@cranberyxl
Created July 27, 2010 20:09
Show Gist options
  • Save cranberyxl/492779 to your computer and use it in GitHub Desktop.
Save cranberyxl/492779 to your computer and use it in GitHub Desktop.
<?php
$filename = "/Andy.jpg";
$min = 800;
list($width, $height) = getimagesize($filename);
$source = imagecreatefromjpeg($filename);
$max = max($height, $width);
if ($min != null && $min > $max) {
$max = $min;
}
$target = imagecreatetruecolor($max, $max);
$white = imagecolorallocate($target, 255, 255, 255);
imagefill($target, 0, 0, $white);
imagecopyresized($target, $source, ($max - $width) / 2, ($max - $height) /2,0, 0, $width, $height, $width, $height);
header('Content-type: image/png');
imagepng($target);
imagedestroy($source);
imagedestroy($target);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment