コード例 #1
0
function smarty_function_generate_resized_image($params)
{
    if ($params['img'] == '') {
        $params['img'] = '/assets/images/not-found.gif';
    }
    $type = '';
    $pathBits = explode('/', $params['img']);
    if (!empty($pathBits[2])) {
        $type = $pathBits[2];
    }
    $img = array_pop($pathBits);
    $dir = array_pop($pathBits);
    //$path = implode('/', $pathBits);
    $path = '/assets/images/resized/';
    $path .= substr($img, 0, 1) . '/';
    $path .= substr($img, 1, 1) . '/';
    $path .= substr($img, 2, 1) . '/';
    //Debugger::debug($path);
    if (!is_dir(PUBLIC_ROOT . $path)) {
        //Debugger::debug(PUBLIC_ROOT . $path, '$path');
        mkdir(PUBLIC_ROOT . $path, 0777, true);
    }
    $nameBits = explode('.', $img);
    $ext = array_pop($nameBits);
    $filename = $path . implode('.', $nameBits) . '_' . $params['width'] . '.' . $ext;
    $key = Image::createKey($img, $params['width']);
    return '<img src="' . $filename . '?key=' . $key . '&type=' . $type . '"  />';
    return '<img src="' . $filename . '?key=' . $key . '" width="' . $params['width'] . '" />';
}
コード例 #2
0
<?php

require_once "../bootstrap.php";
use Lib\Utils\Debugger;
use Lib\ImageTools\Image;
$pathBits = explode('/', $_GET['img']);
dump($_GET);
$image = array_pop($pathBits);
$imgBits = explode('_', $image);
dump($pathBits);
$pathBits[2] = 'original';
$sizeBit = array_pop($imgBits);
$details = explode('.', $sizeBit);
$width = $details[0];
$ext = $details[1];
$imgName = 'assets/' . implode('/', $pathBits) . '/' . implode('_', $imgBits) . '.' . $ext;
//dump($imgName);
$imageResizer = new Image(PUBLIC_ROOT . $imgName);
$testKey = $imageResizer->createKey($imgBits[0] . '.jpg', $width);
//Debugger::debug($testKey);
if ($testKey != $_GET['key']) {
    Debugger::debug('BAD KEY');
} else {
    Debugger::debug('resizing');
    $imageResizer->resize($imgName, $width, PUBLIC_ROOT . 'assets/' . $_GET['img']);
}
$imageResizer->output();