Example #1
0
function fetch_jpeg($url)
{
    $d = __DIR__ . '/cache';
    $md5 = md5($url);
    $file = "{$d}/{$md5}.jpg";
    $file_thumb = "{$d}/{$md5}-150.jpg";
    if (!file_exists($file)) {
        $contents = @file_get_contents($url);
        if ($contents === false) {
            throw new Exception("Could not download {$url}\n\n" . error_get_last()['message']);
        }
        if (!@file_put_contents($file, $contents)) {
            throw new Exception("Could not store {$url}\n\n" . error_get_last()['message']);
        }
    }
    if (!file_exists($file_thumb)) {
        $error = image_thumbnail($file, $file_thumb, 150);
        if (!empty($error)) {
            throw new Exception("Could not create thumbnail file\n\n" . $error);
        }
    }
    return 'data:image/png;base64,' . base64_encode(file_get_contents($file_thumb));
}
            data_fetch("id", "SELECT LAST_INSERT_ID() AS `id`");
            $upload_file = "tattoo" . $id_data['id'] . ".png";
            $image_src = imagecreatefrompng($_FILES['upload_file']['tmp_name']);
            imagecopyresized($image_dest, $image_src, 0, 0, 0, 0, $image_width, $image_height, $upload_fileinfo[0], $upload_fileinfo[1]);
            imagepng($image_dest, $upload_dir . $upload_file);
            break;
        default:
            header("Location: http://" . $_SERVER['HTTP_HOST'] . "/Members/admin/image.construct.tattoo1.php?error=1");
            exit;
    }
    imagedestroy($image_src);
    imagedestroy($image_dest);
    // create preview
    image_preview($id_data['id'], 15);
    header("Location: http://" . $_SERVER['HTTP_HOST'] . "/Members/admin/image.construct.tattoo2.php?id=" . $id_data['id']);
    exit;
} elseif ($_GET['step'] == 2) {
    // update database
    mysql_query("UPDATE `subrosian_tattoos` SET `x`=" . $_POST['tattoo_x'] . ", `y`=" . $_POST['tattoo_y'] . ", `scale`=" . $_POST['tattoo_scale'] . ", `rotation`=" . $_POST['tattoo_rotation'] . ", `strength`=" . $_POST['tattoo_strength'] . " WHERE `id`=" . $_GET['id']);
    // create preview
    image_preview($_GET['id']);
    header("Location: http://" . $_SERVER['HTTP_HOST'] . "/Members/admin/image.construct.tattoo2.php?id=" . $_GET['id']);
    exit;
} elseif ($_GET['step'] == 3) {
    // finalize tattoo
    mysql_query("UPDATE `subrosian_tattoos` SET `ready`=1 WHERE `id`=" . $_GET['id']);
    // create thumbnail
    image_thumbnail($_GET['id']);
    header("Location: http://" . $_SERVER['HTTP_HOST'] . "/Members/admin/image.messages.php?id=3");
    exit;
}