Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
html_image
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Language: Russian
View previous topic :: View next topic  
Author Message
Serzhik
Smarty Rookie


Joined: 12 Mar 2004
Posts: 16
Location: Kyiv, Ukraine

PostPosted: Fri Jul 30, 2004 2:15 pm    Post subject: html_image Reply with quote

Написал некоторое дополнение к стандартной функции. С помощью него можно ограничить размер по ширине и/или по высоте, после чего она будет выдана пользователю в соотетствующей пропорции не нарушая граничных значений.

Если кого-то заинтересовало - обращайтесь
_________________
http://party.com.ua
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Micha
Smarty Rookie


Joined: 28 Aug 2004
Posts: 9

PostPosted: Sat Aug 28, 2004 1:55 am    Post subject: Reply with quote

Да мне интерессно, как можно заполучит?

Зарание спасибо
Back to top
View user's profile Send private message
Serzhik
Smarty Rookie


Joined: 12 Mar 2004
Posts: 16
Location: Kyiv, Ukraine

PostPosted: Sat Aug 28, 2004 3:33 am    Post subject: Reply with quote

Мой e-mail: serzhik[at]ukrpost.net
Напишите мне и я Вам вышлю то что у меня есть...
_________________
http://party.com.ua
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
nihihi
Smarty n00b


Joined: 04 Sep 2004
Posts: 4
Location: Kiev, Ukraine

PostPosted: Sat Sep 04, 2004 2:13 pm    Post subject: Reply with quote

привет!
запость, плз, на этот форум - мне эта функция интересна.
Back to top
View user's profile Send private message Visit poster's website
Serzhik
Smarty Rookie


Joined: 12 Mar 2004
Posts: 16
Location: Kyiv, Ukraine

PostPosted: Sat Sep 04, 2004 11:53 pm    Post subject: Reply with quote

Я не проверял.. Просто быстренько написал. Если будут ошибки - пишите Wink
Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {html_image} function plugin
 *
 * Type:     function<br>
 * Name:     html_image<br>
 * Date:     Feb 24, 2003<br>
 * Purpose:  format HTML tags for the image<br>
 * Input:<br>
 *         - file = file (and path) of image (required)
 *         - border = border width (optional, default 0)
 *         - height = image height (optional, default actual height)
 *         - width = image width (optional, default actual width)
 *         - resize = resize or not picture to used width or height (optional, default false)
 *         - basedir = base directory for absolute paths, default
 *                     is environment variable DOCUMENT_ROOT
 *
 * Examples: {html_image file="images/masthead.gif"}
 * Output:   <img src="images/masthead.gif" border=0 width=400 height=23>
 * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
 *      (Smarty online manual)
 * @author   Monte Ohrt <monte@ispi.net>
 * @author credits to Duda <duda@big.hu> - wrote first image function
 *           in repository, helped with lots of functionality
 * @version  1.0
 * @param array
 * @param Smarty
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_html_image($params, &$smarty)
{
    require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
   
    $alt = '';
    $file = '';
    $border = 0;
    $height = '';
    $width = '';
    $extra = '';
    $prefix = '';
    $suffix = '';
   $resize = false;
    $basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
        ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '';
    if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {
        $dpi_default = 72;
    } else {
        $dpi_default = 96;
    }

    foreach($params as $_key => $_val) {
        switch($_key) {
            case 'file':
            case 'border':
            case 'height':
            case 'width':
            case 'dpi':
            case 'basedir':
                $$_key = $_val;
                break;

            case 'alt':
                if(!is_array($_val)) {
                    $$_key = smarty_function_escape_special_chars($_val);
                } else {
                    $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
                }
                break;

            case 'link':
            case 'href':
                $prefix = '<a href="' . $_val . '">';
                $suffix = '</a>';
                break;
           case 'resize':
               $$_key = (bool)$_val;
            break;

            default:
                if(!is_array($_val)) {
                    $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
                } else {
                    $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
                }
                break;
        }
    }

    if (empty($file)) {
        $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
        return;
    }

    if (substr($file,0,1) == '/') {
        $_image_path = $basedir . $file;
    } else {
        $_image_path = $file;
    }

   // if "resize" parameter is not given, behave as usual
   if ($resize) {
        if(!$_image_data = @getimagesize($_image_path)) {
            if(!file_exists($_image_path)) {
                $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
                return;
            } else if(!is_readable($_image_path)) {
                $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
                return;
            } else {
                $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
                return;
            }
        }

      // compute original image ratio: width/height
      $img_ratio = floatval($_image_data[0])/floatval($_image_data[1]) ;
      $img_ratio = ($img_ratio <= floatval(0)) ? 1 : $img_ratio;
      
      if (isset($params['width']) && isset($params['height'])) {
         $resize_ratio = min(floatval($width)/floatval($_image_data[0]),floatval($height)/floatval($_image_data[1]));
         $resize_ratio = ($resize_ratio <= floatval(0)) ? 1 : $resize_ratio;

         $width=$_image_data[0]*$resize_ratio;
         $height=$_image_data[1]*$resize_ratio;
      } elseif (isset($params['width'])) {
         if ($params['width']<$_image_data[0]) {
            $height = intval(floatval($width) / $img_ratio);
            $height = ($height <= 0) ? 1 : $height;
         } else {
            $width = $_image_data[0];
            $height = $_image_data[1];
         }
      } elseif (isset($params['height'])) {
         if ($params['height']<$_image_data[1]) {
            $width = intval($img_ratio * floatval($height));
            $width = ($width <= 0) ? 1 : $width;
         } else {
            $width = $_image_data[0];
            $height = $_image_data[1];
         }
      }
   }

    if(!isset($params['width']) || !isset($params['height'])) {
        if(!$_image_data = @getimagesize($_image_path)) {
            if(!file_exists($_image_path)) {
                $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
                return;
            } else if(!is_readable($_image_path)) {
                $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
                return;
            } else {
                $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
                return;
            }
        }
        $_params = array('resource_type' => 'file', 'resource_name' => $_image_path);
        require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');
        if(!$smarty->security && !smarty_core_is_secure($_params, $smarty)) {
            $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
            return;
        }

      if(!isset($params['width'])) {
         $width = $_image_data[0];
      }
      if(!isset($params['height'])) {
         $height = $_image_data[1];
      }
    }

    if(isset($params['dpi'])) {
        $_resize = $dpi_default/$params['dpi'];
        $width = round($width * $_resize);
        $height = round($height * $_resize);
    }

    return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
}

/* vim: set expandtab: */

?>

_________________
http://party.com.ua
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mambur
Smarty n00b


Joined: 27 Apr 2005
Posts: 1
Location: Kiev, Ukraine

PostPosted: Wed Apr 27, 2005 10:09 am    Post subject: add to html_image atribute default for show if image not fou Reply with quote

Как насчет добавить в качестве атрибутов к html_image параметр default, для того чтоб если отсутствует картинка на диске отображался текст из default.
Я бы мог это сделать исключительно у себя, но не хочется при обновлении смарти каждый раз вносить изменения. Программировать тут сами понимаете, аж пол строки.
Если кто общается с разработчиками можете грамотно изложить на англицком. Спасибо.
_________________
Hosting provider www.hive.kiev.ua
Back to top
View user's profile Send private message Visit poster's website
Serzhik
Smarty Rookie


Joined: 12 Mar 2004
Posts: 16
Location: Kyiv, Ukraine

PostPosted: Wed Apr 27, 2005 10:20 am    Post subject: Reply with quote

Кстати, очень полезно!

P.S. Сколько я не писал им, об изменении html_image - они менять его не хотят...
_________________
http://party.com.ua
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
AntonT
Smarty n00b


Joined: 21 Nov 2006
Posts: 2
Location: Russia

PostPosted: Fri Jan 26, 2007 9:59 pm    Post subject: Reply with quote

? ??????? ?????? ???? ?? ????????? ??????? ?? smarty ?????? ??????,

? ??? ?????????? ?? ????????? =)
_________________
Sorry for my English
Back to top
View user's profile Send private message
AntonT
Smarty n00b


Joined: 21 Nov 2006
Posts: 2
Location: Russia

PostPosted: Fri Jan 26, 2007 10:00 pm    Post subject: Reply with quote

? ??????? ?????? ???? ?? ????????? ??????? ?? smarty ?????? ??????,

? ??? ?????????? ?????????? =)
_________________
Sorry for my English
Back to top
View user's profile Send private message
AntonT
Smarty n00b


Joined: 21 Nov 2006
Posts: 2
Location: Russia

PostPosted: Fri Jan 26, 2007 10:00 pm    Post subject: ? ??????? ?????? Reply with quote

? ??????? ?????? ???? ?? ????????? ??????? ?? smarty ?????? ??????,

? ??? ?????????? ?????????? =)
_________________
Sorry for my English
Back to top
View user's profile Send private message
RomeO_rzn
Smarty n00b


Joined: 01 Oct 2007
Posts: 0

PostPosted: Tue Oct 02, 2007 10:50 am    Post subject: Reply with quote

>??? ?????? ???????? ? ???????? ????????? ? html_image ???????? default, ??? ???? ???? ???? ??????????? ???????? ?? ????? ??????????? ????? ?? default.

??? ?????? ???????? ???: {html_image file=$PRODUCTS_IMAGE|default:"/images/noimage.jpg" alt=$PRODUCTS_NAME}
?? ? ????????? ?????? ??????????? ?????? ???? ??????? ????????? ??? ? ????? Sad
???????? ??????? ???? function.html_image.php
Back to top
View user's profile Send private message
numberten
Smarty Rookie


Joined: 06 May 2009
Posts: 6

PostPosted: Wed May 06, 2009 10:53 am    Post subject: Reply with quote

{html_image file=$PRODUCTS_IMAGE|default:"/images/noimage.jpg" alt=$PRODUCTS_NAME}
?? ? ????????? ?????? ??????????? ?????? ???? ??????? ????????? ??? ? ?????
???????? ??????? ???? function.html_image.php
Back to top
View user's profile Send private message
DiscoInferno
Smarty Rookie


Joined: 09 Aug 2011
Posts: 20
Location: Moscow, Russia.

PostPosted: Tue Aug 09, 2011 9:27 am    Post subject: Reply with quote

Serzhik wrote:
Я не проверял.. Просто быстренько написал. Если будут ошибки - пишите Wink


Как же, вы создатель не проверяли свое тварение?...
Back to top
View user's profile Send private message Visit poster's website
kiler6
Smarty n00b


Joined: 11 Oct 2013
Posts: 2

PostPosted: Fri Oct 11, 2013 9:16 pm    Post subject: Reply with quote

Очень просто быстро нада было. Плюс ни кто же не сказал что на 100 процентов рабочее творение.





templates for photoshop
underwear shop
Back to top
View user's profile Send private message
havytab88
Smarty n00b


Joined: 21 Nov 2013
Posts: 1
Location: Gaspra

PostPosted: Thu Nov 21, 2013 6:50 pm    Post subject: Reply with quote

Похоже, что работает, спустя 2 года есть ответ Razz Но в целом то неплохо.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Language: Russian All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP