Skip to content

Instantly share code, notes, and snippets.

@sashabeep
Created February 1, 2022 07:48
Show Gist options
  • Save sashabeep/99341e33853cc648c13117e29b1e2101 to your computer and use it in GitHub Desktop.
Save sashabeep/99341e33853cc648c13117e29b1e2101 to your computer and use it in GitHub Desktop.
Phpthumb simpla

1 залить phpthumb с гитхаба в корень /phpthumb, не забыть создать папку cache внутри с 777 и задать стойкий пароль $PHPTHUMB_CONFIG['high_security_password']

2 Добавить функцию в Smarty/libs/plugins/function.phpthumb.php:

<?php

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 *
 * Smarty {phpthumb} function plugin
 *
 * Type:     function<br>
 * Name:     phpthumb<br>
 * Purpose:  riscrittura di un link integrando la libreria phpthumb<br>
 * @author   Somma Michele draco88[at]hotmail.it
 * @param array
 * @param Smarty
 * @return string
 * {phpthumb path='path/to/image' attr1=$attr1 atrr2=$attr2  ...attrN=$attrN}
 * {phpthumb path='images/immagine.jpg' w=100 h=50 zc='l'}
 * {phpthumb path='images/immagine.jpg' wh=100}
 */


require_once($DOCUMENT_ROOT.'phpthumb/phpThumb.config.php');

function smarty_function_phpthumb($params, &$smarty)
{
    if (empty($params['path'])) {
        $smarty->trigger_error("assign: variabile 'path' mancante");
        return;
    }

    $phpthumb = "src=";
    $link= $phpthumb.$params['path'];




    foreach ($params as $k=>$v){
        if ($k!="path") {
            /*eccezzioni*/
            switch ($k) {
                case "wh":
                    $link .= "&w=$v";
                    $link .= "&h=$v";
                    ;
                    break;

                default:
                    $link .= "&$k=$v";

                    break;
            }


        }
    }

    // if(!isset($params['zc'])){
    //     $link .= "&zc=l";
    // }

    $link = htmlspecialchars(phpThumbURL($link, '/phpthumb/phpThumb.php'));


    return $link;
}

Вызов в шаблоне: Сграбить полный путь к картинке со слешом в начале, но без адреса сайта:

{capture assign=brandimage}/{$config->brands_images_dir}{$b->image}{/capture}
{* или в списке в блоге типа *}
{capture assign=image}/{$config->blog_images_dir}{$post->image}{/capture}

и вызов:

<img src="{phpthumb path=$image w=370 h=250 zc='1'}" alt="{$post->name|escape}">
<img src="{phpthumb path=$brandimage h=60}" alt="{$b->name|escape}">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment