zencart 网站与图片分开处理 我是在1.5版本的基础上测试的。
在includes文件夹中defined_paths.php文件配置
在
[php]if (!defined(‘DIR_WS_IMAGES’)) define(‘DIR_WS_IMAGES’, ‘images/’);[/php]
前面添加一句
[php]define(‘HTTP_SERVER_IMG’, ‘http://img.cngoshop.com/’);[/php]
也可以把http://img.cngoshop.com/网址放到
[php]if (!defined(‘DIR_WS_IMAGES’)) define(‘DIR_WS_IMAGES’, ‘http://img.cngoshop.com/images/’);[/php]
我经过测试图片很大,显示的是原始图片大小。如果有这个技术可以技术修改代码处理。
我那种也还是需要修改代码的
找到includes/functions/html_output.php
在[php]function zen_image($src, $alt = ”, $width = ”, $height = ”, $parameters = ”) {[/php]下修改
修改后代码
[php]
function zen_image($src, $alt = ”, $width = ”, $height = ”, $parameters = ”) {
global $template_dir, $zco_notifier;
// 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;
$zco_notifier->notify(‘NOTIFY_HANDLE_IMAGE’, array($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 if (substr($src, 0, 4) != ‘http’) {
$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;
}
[/php]
这样你的图片和网站就分开处理放了。
如果你网站是在后台添加产品一个一个上传的话,也要进行处理。我的是通过Easy Populate批量上传的。在后台就没进行处理了。
发表评论