Skip to content

Instantly share code, notes, and snippets.

@felipap
Created December 19, 2012 05:27
Show Gist options
  • Save felipap/4334586 to your computer and use it in GitHub Desktop.
Save felipap/4334586 to your computer and use it in GitHub Desktop.
<?php
function stickFile ($file, $x, $y)
{
global $dest;
$img = imagecreatefromjpeg($file["tmp_name"]);
$thumb = imagecreatetruecolor(150, 150);
list($width, $height) = getimagesize($file["tmp_name"]);
$side = $width>$height?$height:$width;
// echo "$side ", ($width-$side)/2, " ", ($height-$side)/2, "<br>";
imagecopyresized($thumb, $img,
0, 0, ($width-$side)/2, ($height-$side)/2,
150, 150, $side, $side
);
$nome = $file["name"];
// imagejpeg($thumb, "/var/www/colagem/thumbnails/$nome");
// move_uploaded_file($file["tmp_name"], "/var/www/colagem/uploads/$nome");
imagecopymerge($dest, $thumb, $x, $y, 0, 0, 150, 150, 100);
}
// ////////////////////////////////////////
function putImageTogether () {
global $dest;
header('Content-Type: image/jpeg');
$dest = imagecreatetruecolor(450, 450);
for ($i=0; array_key_exists("img${i}", $_FILES) && $_FILES["img${i}"]["name"]; $i++) {
$file = $_FILES["img${i}"];
stickFile($file, $i%3*150, ($i-$i%3)/3*150);
}
imagejpeg($dest);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
putImageTogether();
} else { // GET method
?>
<html>
<head>
</head>
<body>
<div style="font-family: Georgia;">
<h2>Colagem</h2>
<h5>Entre com os arquivos...</h5>
<form action="colagem.php" method="post" enctype="multipart/form-data">
<formset>
</formset>
<input type="submit" value="Fazer montagem" />
</form>
</div>
<script>
for (var i=0; i<9; i++) {
var div = document.createElement("div");
div.innerHTML = "Arquivo "+window.i+": <input type='file' name='img"+window.i+"' /><br>";
document.querySelector("form formset").appendChild(div);
}
</script>
</body>
</html>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment