zencart zen_image函数介绍
函数原型代码
function zen_image($src, $alt = ”, $width = ”, $height = ”, $parameters = ”) {
global $template_dir;
// soft clean the alt tag
$alt = zen_clean_html($alt);
// use old method on template images
if (strstr($src, ‘includes/templates’) or strstr($src, ‘includes/languages’) or PROPORTIONAL_IMAGES_STATUS == ’0′) {
return zen_image_OLD($src, $alt, $width, $height, $parameters);
}
//auto replace with defined missing image
if ($src == DIR_WS_IMAGES and PRODUCTS_IMAGE_NO_IMAGE_STATUS == ’1′) {
$src = DIR_WS_IMAGES . PRODUCTS_IMAGE_NO_IMAGE;
}
if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == ‘false’) ) {
return false;
}
// if not in current template switch to template_default
if (!file_exists($src)) {
$src = str_replace(DIR_WS_TEMPLATES . $template_dir, DIR_WS_TEMPLATES . ‘template_default’, $src);
}
// hook for handle_image() function such as Image Handler etc
if (function_exists(‘handle_image’)) {
$newimg = handle_image($src, $alt, $width, $height, $parameters);
list($src, $alt, $width, $height, $parameters) = $newimg;
}
// Convert width/height to int for proper validation.
// intval() used to support compatibility with plugins like image-handler
$width = empty($width) ? $width : intval($width);
$height = empty($height) ? $height : intval($height);
// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default
$image = ‘<img src=”‘ . zen_output_string($src) . ‘” alt=”‘ . zen_output_string($alt) . ‘”‘;
if (zen_not_null($alt)) {
$image .= ‘ title=” ‘ . zen_output_string($alt) . ‘ “‘;
}
if ( ((CONFIG_CALCULATE_IMAGE_SIZE == ‘true’) && (empty($width) || empty($height))) ) {
if ($image_size = @getimagesize($src)) {
if (empty($width) && zen_not_null($height)) {
$ratio = $height / $image_size[1];
$width = $image_size[0] * $ratio;
} elseif (zen_not_null($width) && empty($height)) {
$ratio = $width / $image_size[0];
$height = $image_size[1] * $ratio;
} elseif (empty($width) && empty($height)) {
$width = $image_size[0];
$height = $image_size[1];
}
} elseif (IMAGE_REQUIRED == ‘false’) {
return false;
}
}
if (zen_not_null($width) && zen_not_null($height) and file_exists($src)) {
// $image .= ‘ width=”‘ . zen_output_string($width) . ‘” height=”‘ . zen_output_string($height) . ‘”‘;
// proportional images
$image_size = @getimagesize($src);
// fix division by zero error
$ratio = ($image_size[0] != 0 ? $width / $image_size[0] : 1);
if ($image_size[1]*$ratio > $height) {
$ratio = $height / $image_size[1];
$width = $image_size[0] * $ratio;
} else {
$height = $image_size[1] * $ratio;
}
// only use proportional image when image is larger than proportional size
if ($image_size[0] < $width and $image_size[1] < $height) {
$image .= ‘ width=”‘ . $image_size[0] . ‘” height=”‘ . intval($image_size[1]) . ‘”‘;
} else {
$image .= ‘ width=”‘ . round($width) . ‘” height=”‘ . round($height) . ‘”‘;
}
} else {
// override on missing image to allow for proportional and required/not required
if (IMAGE_REQUIRED == ‘false’) {
return false;
} else {
$image .= ‘ width=”‘ . intval(SMALL_IMAGE_WIDTH) . ‘” height=”‘ . intval(SMALL_IMAGE_HEIGHT) . ‘”‘;
}
}
// inject rollover class if one is defined. NOTE: This could end up with 2 “class” elements if $parameters contains “class” already.
if (defined(‘IMAGE_ROLLOVER_CLASS’) && IMAGE_ROLLOVER_CLASS != ”) {
$parameters .= (zen_not_null($parameters) ? ‘ ‘ : ”) . ‘class=”rollover”‘;
}
// add $parameters to the tag output
if (zen_not_null($parameters)) $image .= ‘ ‘ . $parameters;
$image .= ‘ />’;
return $image;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?