Example #1
0
function renderImage($data)
{
    $hash = $data['hash'];
    if ($data['changecode']) {
        $changecode = $data['changecode'];
        unset($data['changecode']);
    }
    $pm = new PictshareModel();
    $base_path = ROOT . DS . 'upload' . DS . $hash . DS;
    $path = $base_path . $hash;
    $type = $pm->isTypeAllowed($pm->getTypeOfFile($path));
    $cached = false;
    $cachename = $pm->getCacheName($data);
    $cachepath = $base_path . $cachename;
    if (file_exists($cachepath)) {
        $path = $cachepath;
        $cached = true;
    } else {
        if (MAX_RESIZED_IMAGES > -1 && $pm->countResizedImages($hash) > MAX_RESIZED_IMAGES) {
            //if the number of max resized images is reached, just show the real one
            $path = ROOT . DS . 'upload' . DS . $hash . DS . $hash;
        }
    }
    switch ($type) {
        case 'jpg':
            header("Content-type: image/jpeg");
            $im = imagecreatefromjpeg($path);
            if (!$cached) {
                if ($pm->changeCodeExists($changecode)) {
                    changeImage($im, $data);
                    imagejpeg($im, $cachepath, 95);
                }
            }
            imagejpeg($im);
            break;
        case 'png':
            header("Content-type: image/png");
            $im = imagecreatefrompng($path);
            if (!$cached) {
                if ($pm->changeCodeExists($changecode)) {
                    changeImage($im, $data);
                    imagepng($im, $cachepath, 1);
                }
            }
            imageAlphaBlending($im, true);
            imageSaveAlpha($im, true);
            imagepng($im);
            break;
        case 'gif':
            header("Content-type: image/gif");
            $im = imagecreatefromgif($path);
            readfile($path);
            break;
    }
    exit;
}
Example #2
0
 function getImage($hash, $size = false)
 {
     $path = ROOT . DS . 'upload' . DS . $hash . DS;
     $fullpath = ROOT . DS . 'upload' . DS . $hash . DS . $hash;
     $pm = new PictshareModel();
     $type = $pm->isTypeAllowed($pm->getTypeOfFile($fullpath));
     if (!$type) {
         return false;
     }
     if (is_array($size)) {
         $width = $size[0];
         $height = $size[1];
     } else {
         if ($size) {
             $width = $size;
             $height = $size;
         }
     }
     if ($width && $height && $type != 'gif') {
         $filename = $width . 'x' . $height . '_' . $hash;
     } else {
         $filename = $hash;
     }
     if (file_exists($path . $filename)) {
         return '/' . $filename;
     }
     $thumb = new easyphpthumbnail();
     if ($width == $height) {
         $thumb->Thumbsize = $width;
     } else {
         $size = getimagesize($fullpath);
         if ($width / $height == $size[0] / $size[1]) {
             $thumb->Thumbwidth = $width;
             $thumb->Thumbheight = $height;
         } else {
             if ($width > $height) {
                 $thumb->Thumbsize = $height;
             } else {
                 $thumb->Thumbsize = $width;
             }
         }
         //$thumb -> Thumbwidth = $width;
         //$thumb -> Thumbheight = $height;
     }
     $thumb->Inflate = false;
     $thumb->Thumblocation = $path;
     //$thumb -> Thumbsaveas = $type;
     $thumb->Thumbfilename = $filename;
     $thumb->Createthumb($fullpath, 'file');
     //var_dump($thumb -> Thumblocation.$thumb -> Thumbfilename);
     return '/' . $filename;
 }
Example #3
0
 /**
  * From: https://stackoverflow.com/questions/4590441/php-thumbnail-image-resizing-with-proportions
  */
 function resize(&$img, $size)
 {
     $pm = new PictshareModel();
     $sd = $pm->sizeStringToWidthHeight($size);
     $maxwidth = $sd['width'];
     $maxheight = $sd['height'];
     $width = imagesx($img);
     $height = imagesy($img);
     if (!ALLOW_BLOATING) {
         if ($maxwidth > $width) {
             $maxwidth = $width;
         }
         if ($maxheight > $height) {
             $maxheight = $height;
         }
     }
     if ($height > $width) {
         $ratio = $maxheight / $height;
         $newheight = $maxheight;
         $newwidth = $width * $ratio;
     } else {
         $ratio = $maxwidth / $width;
         $newwidth = $maxwidth;
         $newheight = $height * $ratio;
     }
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     $palsize = ImageColorsTotal($img);
     for ($i = 0; $i < $palsize; $i++) {
         $colors = ImageColorsForIndex($img, $i);
         ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
     }
     imagefill($newimg, 0, 0, IMG_COLOR_TRANSPARENT);
     imagesavealpha($newimg, true);
     imagealphablending($newimg, true);
     imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     $img = $newimg;
 }
Example #4
0
    exit('Rename /inc/example.config.inc.php to /inc/config.inc.php first!');
}
include_once ROOT . DS . 'inc' . DS . 'config.inc.php';
if (FORCE_DOMAIN) {
    define('DOMAINPATH', FORCE_DOMAIN);
} else {
    define('DOMAINPATH', (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/');
}
error_reporting(E_ALL & ~E_NOTICE);
if (SHOW_ERRORS) {
    ini_set('display_errors', 'On');
} else {
    ini_set('display_errors', 'Off');
}
include_once ROOT . DS . 'inc' . DS . 'core.php';
$pm = new PictshareModel();
if (UPLOAD_CODE != false && !$pm->uploadCodeExists($_REQUEST['upload_code'])) {
    exit(json_encode(array('status' => 'ERR', 'reason' => 'Wrong upload code provided')));
}
if ($_REQUEST['getimage']) {
    $url = $_REQUEST['getimage'];
    echo json_encode($pm->uploadImageFromURL($url));
} else {
    if ($_FILES['postimage']) {
        $image = $_FILES['postimage'];
        echo json_encode($pm->processSingleUpload($file, 'postimage'));
    } else {
        if ($_REQUEST['base64']) {
            $data = $_REQUEST['base64'];
            $format = $_REQUEST['format'];
            echo json_encode($pm->uploadImageFromBase64($data, $format));
Example #5
0
function renderMP4($path, $data)
{
    $pm = new PictshareModel();
    $hash = $data['hash'];
    $urldata = $pm->getURLInfo($path, true);
    if ($data['size']) {
        $hash = $data['size'] . '/' . $hash;
    }
    $info = $pm->getSizeOfMP4($path);
    $width = $info['width'];
    $height = $info['height'];
    $filesize = $urldata['humansize'];
    include ROOT . DS . 'template_mp4.php';
}
Example #6
0
    exit('Rename /inc/example.config.inc.php to /inc/config.inc.php first!');
}
include_once ROOT . DS . 'inc' . DS . 'config.inc.php';
if (FORCE_DOMAIN) {
    define('DOMAINPATH', FORCE_DOMAIN);
} else {
    define('DOMAINPATH', (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/');
}
error_reporting(E_ALL & ~E_NOTICE);
if (SHOW_ERRORS) {
    ini_set('display_errors', 'On');
} else {
    ini_set('display_errors', 'Off');
}
include_once ROOT . DS . 'inc' . DS . 'core.php';
$pm = new PictshareModel();
if (UPLOAD_CODE != false && !$pm->uploadCodeExists($_REQUEST['upload_code'])) {
    exit(json_encode(array('status' => 'ERR', 'reason' => 'Wrong upload code provided')));
}
if ($_REQUEST['getimage']) {
    $url = $_REQUEST['getimage'];
    echo json_encode($pm->uploadImageFromURL($url));
} else {
    if ($_FILES['postimage']) {
        $image = $_FILES['postimage'];
        echo json_encode($pm->processSingleUpload($file, 'postimage'));
    } else {
        if ($_REQUEST['base64']) {
            $data = $_REQUEST['base64'];
            $format = $_REQUEST['format'];
            echo json_encode($pm->uploadImageFromBase64($data, $format));