View previous topic :: View next topic |
Author |
Message |
Serzhik Smarty Rookie
Joined: 12 Mar 2004 Posts: 18 Location: Kyiv, Ukraine
|
Posted: Fri Jul 30, 2004 2:15 pm Post subject: html_image |
|
|
Написал некоторое дополнение к стандартной функции. С помощью него можно ограничить размер по ширине и/или по высоте, после чего она будет выдана пользователю в соотетствующей пропорции не нарушая граничных значений.
Если кого-то заинтересовало - обращайтесь _________________ http://party.com.ua |
|
Back to top |
|
Micha Smarty Rookie
Joined: 28 Aug 2004 Posts: 9
|
Posted: Sat Aug 28, 2004 1:55 am Post subject: |
|
|
Да мне интерессно, как можно заполучит?
Зарание спасибо |
|
Back to top |
|
Serzhik Smarty Rookie
Joined: 12 Mar 2004 Posts: 18 Location: Kyiv, Ukraine
|
Posted: Sat Aug 28, 2004 3:33 am Post subject: |
|
|
Мой e-mail: serzhik[at]ukrpost.net
Напишите мне и я Вам вышлю то что у меня есть... _________________ http://party.com.ua |
|
Back to top |
|
nihihi Smarty n00b
Joined: 04 Sep 2004 Posts: 4 Location: Kiev, Ukraine
|
Posted: Sat Sep 04, 2004 2:13 pm Post subject: |
|
|
привет!
запость, плз, на этот форум - мне эта функция интересна. |
|
Back to top |
|
Serzhik Smarty Rookie
Joined: 12 Mar 2004 Posts: 18 Location: Kyiv, Ukraine
|
Posted: Sat Sep 04, 2004 11:53 pm Post subject: |
|
|
Я не проверял.. Просто быстренько написал. Если будут ошибки - пишите
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 |
|
mambur Smarty n00b
Joined: 27 Apr 2005 Posts: 1 Location: Kiev, Ukraine
|
Posted: Wed Apr 27, 2005 10:09 am Post subject: add to html_image atribute default for show if image not fou |
|
|
Как насчет добавить в качестве атрибутов к html_image параметр default, для того чтоб если отсутствует картинка на диске отображался текст из default.
Я бы мог это сделать исключительно у себя, но не хочется при обновлении смарти каждый раз вносить изменения. Программировать тут сами понимаете, аж пол строки.
Если кто общается с разработчиками можете грамотно изложить на англицком. Спасибо. _________________ Hosting provider www.hive.kiev.ua |
|
Back to top |
|
Serzhik Smarty Rookie
Joined: 12 Mar 2004 Posts: 18 Location: Kyiv, Ukraine
|
Posted: Wed Apr 27, 2005 10:20 am Post subject: |
|
|
Кстати, очень полезно!
P.S. Сколько я не писал им, об изменении html_image - они менять его не хотят... _________________ http://party.com.ua |
|
Back to top |
|
AntonT Smarty n00b
Joined: 21 Nov 2006 Posts: 2 Location: Russia
|
Posted: Fri Jan 26, 2007 9:59 pm Post subject: |
|
|
? ??????? ?????? ???? ?? ????????? ??????? ?? smarty ?????? ??????,
? ??? ?????????? ?? ????????? =) _________________ Sorry for my English |
|
Back to top |
|
AntonT Smarty n00b
Joined: 21 Nov 2006 Posts: 2 Location: Russia
|
Posted: Fri Jan 26, 2007 10:00 pm Post subject: |
|
|
? ??????? ?????? ???? ?? ????????? ??????? ?? smarty ?????? ??????,
? ??? ?????????? ?????????? =) _________________ Sorry for my English |
|
Back to top |
|
AntonT Smarty n00b
Joined: 21 Nov 2006 Posts: 2 Location: Russia
|
Posted: Fri Jan 26, 2007 10:00 pm Post subject: ? ??????? ?????? |
|
|
? ??????? ?????? ???? ?? ????????? ??????? ?? smarty ?????? ??????,
? ??? ?????????? ?????????? =) _________________ Sorry for my English |
|
Back to top |
|
RomeO_rzn Smarty n00b
Joined: 01 Oct 2007 Posts: 0
|
Posted: Tue Oct 02, 2007 10:50 am Post subject: |
|
|
>??? ?????? ???????? ? ???????? ????????? ? html_image ???????? default, ??? ???? ???? ???? ??????????? ???????? ?? ????? ??????????? ????? ?? default.
??? ?????? ???????? ???: {html_image file=$PRODUCTS_IMAGE|default:"/images/noimage.jpg" alt=$PRODUCTS_NAME}
?? ? ????????? ?????? ??????????? ?????? ???? ??????? ????????? ??? ? ?????
???????? ??????? ???? function.html_image.php |
|
Back to top |
|
numberten Smarty Rookie
Joined: 06 May 2009 Posts: 6
|
Posted: Wed May 06, 2009 10:53 am Post subject: |
|
|
{html_image file=$PRODUCTS_IMAGE|default:"/images/noimage.jpg" alt=$PRODUCTS_NAME}
?? ? ????????? ?????? ??????????? ?????? ???? ??????? ????????? ??? ? ?????
???????? ??????? ???? function.html_image.php |
|
Back to top |
|
DiscoInferno Smarty Rookie
Joined: 09 Aug 2011 Posts: 18 Location: Moscow, Russia.
|
Posted: Tue Aug 09, 2011 9:27 am Post subject: |
|
|
Serzhik wrote: | Я не проверял.. Просто быстренько написал. Если будут ошибки - пишите
|
Как же, вы создатель не проверяли свое тварение?... |
|
Back to top |
|
havytab88 Smarty n00b
Joined: 21 Nov 2013 Posts: 1 Location: Gaspra
|
Posted: Thu Nov 21, 2013 6:50 pm Post subject: |
|
|
Похоже, что работает, спустя 2 года есть ответ Но в целом то неплохо. |
|
Back to top |
|
argoo Smarty n00b
Joined: 20 Nov 2014 Posts: 1
|
Posted: Thu Nov 20, 2014 11:59 am Post subject: |
|
|
Древний город Фенхуан и красота Китая
Фенхуан — древний город в китайской провинции Хунань. Фенхуан в переводе с китайского языка означает "феникс". Поселение хорошо известно своим сохранившимся старым городом, воспетым во многих легендах. Фенхуан находится во власти деревянных зданий на сваях. Город уникален, изящен, окружен живописными реками и горами — время здесь словно остановилось, а сооружения украшены красными китайскими фонарями.
Это действительно волшебное место, которое многие считают самым красивым городом в Китае. Древний город Фенхуан является объектом Всемирного наследия ЮНЕСКО. Древнее сообщество, расположенное в западной части провинции Хунань, более походит на Венецию Востока, только не подверженную модернизации и современному влиянию. Деревянные лодки, простые речные перекрестки, китайские здания на сваях, традиционная еда и одежда — все выглядит так, как будто это место застыло во времени.
Очарование Фенхуана — это нечто выше простой естественной красоты. Во время прогулки по городу можно бесконечно восхищаться красоте древней архитектуры. Большинство узких улочек вымощены булыжником, а в магазинах продают абсолютно странные продукты — от головы свиньи, до мяса полевых крыс.
подробнее тут |
|
Back to top |
|
|