<?php

header('Content-Type: image/jpeg');
require_once $_SERVER['DOCUMENT_ROOT'] . "/generate.class.php";
$username = $_GET["username"];
$profilePictureURL = $_GET["profilePictureURL"];
$photoURL = $_GET["photoURL"];
$creationTime = $_GET["creationTime"];
$location = $_GET["location"];
$caption = $_GET["caption"];
$link = $_GET["link"];
$likes = $_GET["likes"];
$logo = $_GET["logo"];
$printGenerator = new PrintGenerator($username, $location, $caption, $link, $profilePictureURL, $photoURL, $creationTime, $likes, $logo);
$image = $printGenerator->getPrintJpeg();
echo base64_encode($image);
function instagramPrintFromMediaId($mediaId, $clientId)
{
    $curl = curl_init();
    curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => "https://api.instagram.com/v1/media/{$mediaId}?client_id={$clientId}"));
    $responce = curl_exec($curl);
    curl_close($curl);
    $media = json_decode($responce);
    $username = $media->data->user->username;
    $profilePictureURL = $media->data->user->profile_picture;
    $photoURL = $media->data->images->standard_resolution->url;
    $creationTime = $media->data->created_time;
    $location = $media->data->location->name;
    $caption = $media->data->caption->text;
    $likes = $media->data->likes->count;
    $link = $media->data->link;
    $logo = "";
    $printGenerator = new PrintGenerator($username, $location, $caption, $link, $profilePictureURL, $photoURL, $creationTime, $likes, $logo);
    $print = $printGenerator->getPrintJpeg();
    return $print;
}