Example #1
0
function CreateImageToCache($handle, $thumb_w, $thumb_h, $back, $opt, $src)
{
    $remote_image = DetectImage($handle);
    $w = imagesx($remote_image);
    $h = imagesy($remote_image);
    if ($h != 0) {
        $q = $w / $h;
    }
    // Generate size of thumb
    if ($thumb_w == -1 or $thumb_h == -1) {
        if ($thumb_w == -1 and $thumb_h == -1) {
            $thumb_w = $_GET['img_w'];
            $thumb_h = $_GET['img_h'];
        } else {
            if ($thumb_h != -1 and $thumb_w == -1) {
                $thumb_w = (int) $thumb_h * $q;
            }
            if ($thumb_h == -1 and $thumb_w != -1) {
                $thumb_h = (int) $thumb_w / $q;
            }
        }
    }
    // Valid size of the thumb
    if ($thumb_w > 1000) {
        $thumb_w = 650;
    }
    if ($thumb_w < 10) {
        $thumb_w = 10;
    }
    if ($thumb_h > 1000) {
        $thumb_h = 650;
    }
    if ($thumb_h < 10) {
        $thumb_h = 10;
    }
    // create thumb
    $thumb = imagecreatetruecolor($thumb_w, $thumb_h);
    // fill color
    if (is_string($back) && stristr($back, 'transparent')) {
        imagealphablending($thumb, true);
        imagecolortransparent($thumb, imagecolorallocatealpha($thumb, 255, 255, 255, 127));
    } else {
        imagefill($thumb, 0, 0, imagecolorallocate($thumb, $back[0], $back[1], $back[2]));
    }
    imagecopyresampled($thumb, $remote_image, 0, 0, 0, 0, $thumb_w, $thumb_h, $w, $h);
    // Case Corsia
    if ($opt == '_corsia_') {
        //imagefilter($thumb, IMG_FILTER_BRIGHTNESS, 80);
        $src_t = CACHE_DEFAULT . 'em-producao.png';
        list($src_w, $src_h) = getimagesize($src_t);
        $res = imagecreatefrompng($src_t);
        imagealphablending($res, true);
        imagecopymerge($thumb, $res, $thumb_w / 2 - $src_w / 2, $thumb_h - $src_h - 3, 0, 0, $src_w, $src_h, 100);
        imagedestroy($res);
    }
    // Case Reservado
    if ($opt == '_reservado_') {
        $src_t = CACHE_DEFAULT . 'reservado.png';
        list($src_w, $src_h) = getimagesize($src_t);
        $res = imagecreatefrompng($src_t);
        imagealphablending($res, true);
        imagecopymerge($thumb, $res, $thumb_w / 2 - $src_w / 2, $thumb_h - $src_h - 3, 0, 0, $src_w, $src_h, 100);
        imagedestroy($res);
    }
    // Case Vendido
    if ($opt == '_vendido_') {
        $src_t = CACHE_DEFAULT . 'vendido.png';
        list($src_w, $src_h) = getimagesize($src_t);
        $res = imagecreatefrompng($src_t);
        imagealphablending($res, true);
        imagecopymerge($thumb, $res, $thumb_w / 2 - $src_w / 2, $thumb_h - $src_h - 3, 0, 0, $src_w, $src_h, 100);
        imagedestroy($res);
    }
    // Armazena a imagem localmente
    imagejpeg($thumb, $src, 80);
    // Envia a imagem
    SendImageFromCache($src, 0);
}
Example #2
0
        if (FileCacheIsLive($src, $ttl)) {
            SendImageFromCache($src);
        }
    }
    if ($validRemote and !CheckRemoteFile($handle)) {
        DefaultImage();
    }
    CreateImageToCache($handle, $thumb_w, $thumb_h, $back, $opt, $src);
} elseif (isset($_GET['i']) and isset($_GET['o'])) {
    // request param, pre sql injection tratament, remove html and limit string code
    $owner = empty($_GET['o']) ? null : substr(addslashes(strip_tags(trim(preg_replace('/\\s/m', '', $_GET['o'])))), 0, 20);
    $image = preg_replace('/\\.[a-z]+$/i', '', $_GET['i']);
    $index = max((int) filter_input(INPUT_GET, 'e', FILTER_SANITIZE_NUMBER_INT), 1);
    // mount file name cache
    $src = CACHE_DIR . sha1(CACHE_DIR . $image . $owner . $index . $thumb_w . $thumb_h . $quality . $opt . ((!empty($_GET['img_bg']) and count(explode(',', $_GET['img_bg'])) == 3) ? $_GET['img_bg'] : '255,255,255')) . $ext;
    // mount url core integration
    $handle = 'https://core.smartdealer.com.br/img/' . $image . '/' . $owner . '/' . $thumb_w . '/' . $index . '.jpg';
    // check if file exists
    if ($cache && file_exists($src)) {
        if (FileCacheIsLive($src, $ttl)) {
            SendImageFromCache($src);
        }
    }
    if ($validRemote and !CheckRemoteFile($handle)) {
        DefaultImage();
    }
    CreateImageToCache($handle, $thumb_w, $thumb_h, $back, $opt, $src);
} else {
    // invalid request, return default image
    DefaultImage();
}