Ejemplo n.º 1
0
function imageHandler($sourcefile, $savename, $savedir, $widthmax, $heightmax, $quality, $extension)
{
    $destfile = $savedir . "/" . $savename;
    if (file_exists($destfile)) {
        unlink($destfile);
    }
    if (file_exists($sourcefile)) {
        preg_match('/\\.(jpg|png|gif)$/', $sourcefile, $ext);
        $image = new img($sourcefile, $ext[1]);
        //echo $widthmax.'/'.$heightmax;exit();
        $image->resize($widthmax, $heightmax, true);
        $image->store($destfile);
        chmod($destfile, 0777);
    }
}
Ejemplo n.º 2
0
 /**
  * Process images
  * @return string
  */
 protected function imageFile($path)
 {
     $params = array_intersect_key($_GET, array('x' => '', 'y' => '', 'adapt' => '', 'crop' => ''));
     $params['path'] = $path;
     /* Adaptive imgs */
     $resMax = 0;
     if (isset($params['adapt']) && isset($_COOKIE['DW']) && isset($_COOKIE['DH']) && isset($_COOKIE['DPR'])) {
         $resMax = max($_COOKIE['DW'], $_COOKIE['DH']) * (int) $_COOKIE['DPR'];
         $resMax = $params['adapt'] = ceil($resMax / 100) * 100;
         /* to limit amount of cached images versions */
         if (isset($params['x']) && $params['x'] > $resMax) {
             $params['x'] = $resMax;
         }
     }
     $cachePath = 'var/cache/' . str_replace('/', '_', http_build_query($params, '', '_'));
     /* get only allowed vars and secure generated path */
     if (!is_file($cachePath)) {
         /* if cache doesn't exists */
         include 'modules/core/classes/img.php';
         $img = new img($path);
         if (isset($params['x']) && isset($params['y'])) {
             if (isset($params['crop'])) {
                 $img->crop($params['x'], $params['y']);
             } else {
                 $img->resize($params['x'], $params['y']);
             }
         } elseif ($resMax > 0) {
             /* If there isn't x and y params we resize img to max Resolution of user's screen */
             $img->resize($resMax, 9999);
         }
         $img->save($cachePath, 80);
     }
     return $cachePath;
 }
Ejemplo n.º 3
0
<?php

session_start();
if ($_GET['pic']) {
    $img = new img('upload/' . $_GET['pic']);
    $img->resize();
    $img->show();
}
class img
{
    var $image = '';
    var $temp = '';
    function img($sourceFile)
    {
        if (file_exists($sourceFile)) {
            $this->image = ImageCreateFromJPEG($sourceFile);
        } else {
            $this->errorHandler();
        }
        return;
    }
    function resize($width = 400, $height = 400, $aspectradio = true)
    {
        $o_wd = imagesx($this->image);
        $o_ht = imagesy($this->image);
        if (isset($aspectradio) && $aspectradio) {
            $w = round($o_wd * $height / $o_ht);
            $h = round($o_ht * $width / $o_wd);
            if ($height - $h < $width - $w) {
                $width =& $w;
            } else {
Ejemplo n.º 4
0
 static function updateThumbnail($fname, $w, $h, $quality = 25)
 {
     $thumbDir = dirname($fname) . '/.thumbs/';
     $thumbFname = $thumbDir . basename($fname);
     $doUpdate = @filectime($fname) > @filectime($thumbFname);
     if ($doUpdate) {
         // create thumbs dir
         if (!file_exists($thumbDir)) {
             @mkdir($thumbDir);
         }
         // save thumbnail
         $img = new img($fname);
         $img->resize($w, $h);
         file_put_contents($thumbFname, $img->render($quality));
     }
     return $thumbFname;
 }
Ejemplo n.º 5
0
define('PARSER', DIR_LIBS . 'parser.php');
// Libraries
require_once LIBRARY;
// Set REQUEST_URI (IIS does not set 'REQUEST_URI' so concat)
$request_uri = $_SERVER["SCRIPT_NAME"];
if (!empty($_SERVER["QUERY_STRING"])) {
    $request_uri .= "?" . $_SERVER["QUERY_STRING"];
}
// IMAGE RESIZE
if (preg_match(RESIZE, $request_uri, $i)) {
    // get image name
    $filename = DIR_IMG_MAIN . $i[2] . $i[6];
    // keep aspect ratio
    $keep = !empty($i[5]) ? false : true;
    $image = new img($filename, $i[7]);
    $image->resize($i[3], $i[4], !empty($i[5]) ? false : true);
    $image->store(DIR_RESIZED . $i[0]);
    $image->show();
    unset($image);
} elseif (preg_match(WATERMARK, $request_uri, $i)) {
    // get image name
    $filename = DIR_CUR . 'images' . DIR_SEP . $i[2] . '.jpg';
    $image = new img($filename);
    $image->watermark(DIR_CUR . 'images' . DIR_SEP . 'config' . DIR_SEP . 'watermark.png', 10, 10);
    $image->store(DIR_WM . $i[0]);
    $image->show();
    unset($image);
} elseif (preg_match('/\\/([^\\/]+).html$/i', $request_uri, $i)) {
    $parsed =& $i[1];
    header("HTTP/1.0 200 OK");
    require_once DIR_CUR . 'index.php';