예제 #1
0
    try {
        $img = $generator->generate($pos, $template, $overlay);
        $_SESSION['lastPos'] = $_GET['p'];
    } catch (Exception $e) {
        $img = imagecreatefrompng('img/error.png');
    }
} elseif (isset($_GET['t'])) {
    $generator = new ImageGenerator('img/designer/', 'img/template/');
    $result = $db->query("SELECT templateId || '.' || filetype AS file, \n\t\t\t\t\t\t\t\t CASE WHEN overlayFiletype IS NULL THEN null ELSE templateId || '.' || overlayFiletype END AS overlayFile, \n\t\t\t\t\t\t\t\t positions AS pos\n\t\t\t\t\t\t FROM Templates\n\t\t\t\t\t\t WHERE templateId = ?", array($_GET['t']), array(SQLITE3_TEXT));
    if ($db->resultHasRows($result)) {
        $row = $result->fetchArray();
        $templateId = $_GET['t'];
        $file = $row['file'];
        $overlayFile = $row['overlayFile'];
        $pos = $row['pos'];
        $img = $generator->generate($pos, $file, $overlayFile);
    } else {
        $img = imagecreatefrompng('img/error.png');
    }
} else {
    exit;
}
if (isset($_GET['w']) || isset($_GET['h'])) {
    $fullWidth = imagesx($img);
    $fullHeight = imagesy($img);
    $w = isset($_GET['w']) ? $_GET['w'] : $fullWidth * ($_GET['h'] / $fullHeight);
    $h = isset($_GET['h']) ? $_GET['h'] : $fullHeight * ($_GET['w'] / $fullWidth);
    $newimg = imagecreatetruecolor($w, $h);
    imagecopyresampled($newimg, $img, 0, 0, 0, 0, $w, $h, $fullWidth, $fullHeight);
    imagedestroy($img);
    $img = $newimg;
    $_SESSION['lastPos'] = '[]';
    header('Location: designer.php');
    die;
}
if (!isset($_SESSION['lastPos'])) {
    kill();
}
if (strlen($_SESSION['lastPos']) < 5) {
    kill();
    //there probably aren't any boxes drawn if the json is less than 5 chars long
}
try {
    json_decode($_SESSION['lastPos']);
    $json = $_SESSION['lastPos'];
    $generator = new ImageGenerator('img/designer/', '');
    $generator->generate($json, $_SESSION['activeImg']);
} catch (Exception $e) {
    kill();
}
$templateId = $_SESSION['activeId'];
$_SESSION['lastId'] = $_SESSION['activeId'];
//for the success message
$templateFiletype = pathinfo($_SESSION['activeImg'], PATHINFO_EXTENSION);
$pos = $_SESSION['lastPos'];
$overlayFiletype = $_SESSION['activeOverlay'] == '' ? 'NONE' : pathinfo($_SESSION['activeOverlay'], PATHINFO_EXTENSION);
$result = $db->addTemplate($templateId, $pos, $templateFiletype, $overlayFiletype);
if ($result === ';success') {
    $file = pathinfo($_SESSION['activeImg'], PATHINFO_BASENAME);
    $overlayFile = pathinfo($_SESSION['activeOverlay'], PATHINFO_BASENAME);
    rename('img/temp/' . $file, 'img/template/' . $file);
    if ($overlayFile != '') {
예제 #3
0
    die('Insufficient Permissions');
}
if (!$me->getAdmin()->canMakeAdmin()) {
    die('Insufficient Permissions');
}
$count = isset($_GET['count']) ? $_GET['count'] : 10;
echo "Generating " . $_GET['count'] . " memes<br>";
$startingTime = time();
$tempDbLocation = str_replace('.', '-temp.', $db->getLocation());
@unlink($tempDb);
copy($db->getLocation(), $tempDbLocation);
$tempDb = new Database($tempDbLocation);
$templates = $tempDb->getTemplates(isset($_GET['templateQuery']) ? urldecode($_GET['templateQuery']) : "SELECT * FROM Templates WHERE reviewState = 'a'");
$sources = $tempDb->getSourceImages(isset($_GET['sourceQuery']) ? urldecode($_GET['sourceQuery']) : "SELECT * FROM SourceImages WHERE reviewState = 'a'");
$sourcePaths = array();
for ($i = 0; $i < count($sources); $i++) {
    array_push($sourcePaths, $sources[$i]->getImage());
}
$generator = new ImageGenerator('', '');
for ($i = 0; $i < $count; $i++) {
    $t = $templates[mt_rand(0, count($templates) - 1)];
    $img = $generator->generate($t->getPositions(), $t->getImage(), $t->getOverlayImage(), $sourcePaths);
    @unlink("img/output/Meme_{$i}.jpg");
    imagejpeg($img, "img/output/Meme_{$i}.jpg");
}
$db->close();
$tempDb->close();
@unlink($tempDbLocation);
echo "Done.<br>";
echo "Took " . (time() - $startingTime) . ' seconds.';
set_time_limit(30);
include 'php/autoload.php';
if (isset($_GET['p']) && isset($_SESSION['activeImg'])) {
    $generator = new ImageGenerator('img/designer/', '');
    $template = $_SESSION['activeImg'];
    $overlay = $_SESSION['activeOverlay'] === '' ? null : $_SESSION['activeOverlay'];
    $pos = $_GET['p'];
    try {
        $img = $generator->generate($pos, $template, $overlay);
        $_SESSION['lastPos'] = $_GET['p'];
    } catch (Exception $e) {
        $img = imagecreatefrompng('img/error.png');
    }
} elseif (isset($_GET['t'])) {
    $generator = new ImageGenerator('img/designer/', '');
    $template = $db->getTemplates("SELECT Templates.*\n\t\t\t\t\t\t FROM Templates\n\t\t\t\t\t\t WHERE templateId = ?", array($_GET['t']), array(SQLITE3_TEXT))[0];
    $img = $generator->generate($template->getPositions(), $template->getImage(), $template->getOverlayFiletype() === null ? null : $template->getOverlayImage());
} else {
    exit;
}
if (isset($_GET['w']) || isset($_GET['h'])) {
    $fullWidth = imagesx($img);
    $fullHeight = imagesy($img);
    $w = isset($_GET['w']) ? $_GET['w'] : $fullWidth * ($_GET['h'] / $fullHeight);
    $h = isset($_GET['h']) ? $_GET['h'] : $fullHeight * ($_GET['w'] / $fullWidth);
    $newimg = imagecreatetruecolor($w, $h);
    imagecopyresampled($newimg, $img, 0, 0, 0, 0, $w, $h, $fullWidth, $fullHeight);
    imagedestroy($img);
    $img = $newimg;
}
header('Content-Type: image/jpg');
imagejpeg($img);