<?php if (!empty($_POST['login'])) { require_once 'matrix.php'; $handler = new twitterCollageMaker('3640917323-H24Nio9DdFqr0IvC0bCtndbgVYbpWFSo0V7bSqy', '4ErCcdUFH9nD7HoY3qY9KNzXwdTpV34lBPpTmzbXjJPOz', $_POST['login']); $collage = $handler->createCollage($handler->getMust()); echo $collage; } else { ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Twitter</title> <link rel="stylesheet" href="twitterstyle/style.css"> <link rel="stylesheet" href="fancybox/jquery.fancybox.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="fancybox/jquery.fancybox.pack.js"></script> </head> <body> <div class="form_wrapper"> <form action="" method="POST" name="form" id="form"> <span class="input input--kuro"> <input type="text" class="input__field input__field--kuro" name="login" id="login" required> <label for="login" class="input__label input__label--kuro"> <span class="input__label-content input__label-content--kuro">Enter your name</span> </label> </span> <span class="input input--kuro"> <input type="text" class="input__field input__field--kuro" name="option" id="option"> <label for="option" class="input__label input__label--kuro">
public function createCollage($must, $dir = 'images', $ext = 'jpeg') { if (!is_dir($dir)) { $this->error = array("code" => 999, "text" => "No such directory", "method" => __METHOD__); } elseif (!twitterCollageMaker::checkExtension($ext)) { $this->error = array("code" => 999, "text" => "Incorrect extension", "method" => __METHOD__); } if ($this->isError()) { return json_encode($this->error); } $picture = imagecreatetruecolor($this->dimension, $this->dimension); foreach ($must as $one) { if (strpos(strtolower($one['photo']), '.jpg') || strpos(strtolower($one['photo']), '.jpeg')) { $item = imagecreatefromjpeg($one['photo']); } elseif (strpos(strtolower($one['photo']), '.png')) { $item = imagecreatefrompng($one['photo']); } elseif (strpos(strtolower($one['photo']), '.gif')) { $item = imagecreatefromgif($one['photo']); } elseif ($one['photo'] == 'color') { $item = imagecreatetruecolor(1, 1); $color = imagecolorallocate($item, rand(1, 255), rand(1, 255), rand(1, 255)); imagefill($item, 0, 0, $color); } else { continue; } imagecopyresampled($picture, $item, $one['x'] * $this->dimension / 10, $one['y'] * $this->dimension / 10, 0, 0, $one['size'] * $this->dimension / 10, $one['size'] * $this->dimension / 10, imagesx($item), imagesy($item)); } $name = $dir . "/" . time() . "." . $ext; imagejpeg($picture, $name); return json_encode(array('image' => $name)); }