Skip to content

Instantly share code, notes, and snippets.

@useless
Created January 12, 2010 13:31
Show Gist options
  • Save useless/275195 to your computer and use it in GitHub Desktop.
Save useless/275195 to your computer and use it in GitHub Desktop.
Create a combined image. Requires PHP with GD support.
#!/usr/bin/php
<?php
$Images = array();
$img = '';
$r = 0.5;
$H = 300;
$W = 0;
for($i=1; $i<$argc; $i++)
{
if($img=@ImageCreateFromJPEG($argv[$i]))
{
$Images[] = $img;
$W += floor($H*$r*ImageSX($img)/ImageSY($img));
}
}
$back = 0;
if(count($Images))
{
$img = ImageCreateTrueColor($W+(count($Images)+1)*2, $H+4);
$back = ImageColorAllocate($img, 60,60,60);
$bord = ImageColorAllocate($img, 255,255,255);
$shadow = ImageColorAllocateAlpha($img, 0,0,0, 80);
ImageFilledRectangle($img, 0,0, $W+(count($Images)+1)*2, $H+4, $back);
}
$p=2;
foreach($Images as $orig)
{
$ow = ImageSX($orig);
$oh = ImageSY($orig);
$w = floor($H*$r*$ow/$oh);
ImageCopyResampled($img, $orig, $p,2, floor((1.0-$r)*$ow/2),0, $w,$H, floor($r*$ow),$oh);
ImageRectangle($img, $p,2, $p+$w-1,$H+1, $bord);
ImageRectangle($img, $p+1,3, $p+$w-2,$H, $shadow);
$p+=$w+2;
ImageDestroy($orig);
}
Header('Content-type: image/jpeg');
ImageJPEG($img, '', 95);
ImageDestroy($img);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment