存档

2010年9月 的存档

盗梦空间

2010年9月12日 没有评论

准备进场了!

分类: 杂志 标签:

修改virtuemart的图片上传功能

2010年9月8日 7 条评论

有2个图片上传的地方需要修改:

1 默认产品的大图,要把它修改为不管上传的图片多大,都会自动更改为640×480大小。

The solution for this case is to hack the main product image resize to max height/width 600px, open the the file in administrator/components/com_virtuemart/classes/imageTools.class.php file. Locate the following code.

original code

// Resize the Full Image
if( !empty ( $_FILES[$tmp_field_name]["tmp_name"] )) {
	$full_file = $_FILES[$tmp_field_name]["tmp_name"];
	$image_info = getimagesize($full_file);
}

Replace with the following code

// Beginning of Modify by DesignerSandbox
// resize the full product image dynamically and give it maximal dimensions 600x600 during uploading
// Resize the Full Image
if( !empty ( $_FILES[$tmp_field_name]["tmp_name"] )) {
	$full_file = $_FILES[$tmp_field_name]["tmp_name"];

	$image_info = getimagesize($full_file);
	$original_height =  $image_info[1];
	$original_width =  $image_info[0];

	if ($original_height > $original_width) {
		$largewidth = (480 / $original_height) * $original_width;
		$largeheight = "480px";
	} else {
		$largeheight = (640 / $original_width) * $original_height;
		$largewidth = "640px";
	}

	//Get Image size info
	list($original_width, $original_height, $image_type) = getimagesize($full_file);

	switch ($image_type)
	{
		case 1: $im = imagecreatefromgif($full_file); break;
		case 2: $im = imagecreatefromjpeg($full_file);  break;
		case 3: $im = imagecreatefrompng($full_file); break;
		default:  trigger_error('Unsupported filetype!', E_USER_WARNING);  break;
	}

	$big = imagecreatetruecolor($largewidth, $largeheight);

	/* Check if this image is PNG or GIF, then set if Transparent*/
	if(($image_type == 1) OR ($image_type==3))
	{
		imagealphablending($big, false);
		imagesavealpha($big,true);
		$transparent = imagecolorallocatealpha($big, 255, 255, 255, 127);
		imagefilledrectangle($big, 0, 0, $largewidth, $largeheight, $transparent);
	}
	imagecopyresampled($big, $im, 0, 0, 0, 0, $largewidth, $largeheight, $original_width, $original_height);

	//Generate the file, and rename it to $newfilename
	switch ($image_type)
	{
		case 1: imagegif($big,$full_file); break;
		case 2: imagejpeg($big,$full_file);  break;
		case 3: imagepng($big,$full_file); break;
		default:  trigger_error('Er ging iets fout!', E_USER_WARNING);  break;
	}}
// end of edit by DesignerSandbox

2 上传额外的图片时候,把默认的尺寸设置改为640×480:

打开:/administrator/components/com_virtuemart/html/product.file_form.php 文件,

把下列代码:

<?php echo $VM_LANG->_(‘PHPSHOP_PRODUCT_FORM_HEIGHT’);?>: <input type=”text” name=”fullimage_height” value=”500″ />&nbsp;&nbsp;&nbsp;
<?php echo $VM_LANG->_(‘PHPSHOP_PRODUCT_FORM_WIDTH’);?>: <input type=”text” name=”fullimage_width” value=”500″ /></div>

改为:

<?php echo $VM_LANG->_(‘PHPSHOP_PRODUCT_FORM_HEIGHT’);?>: <input type=”text” name=”fullimage_height” value=”480″ />&nbsp;&nbsp;&nbsp;
<?php echo $VM_LANG->_(‘PHPSHOP_PRODUCT_FORM_WIDTH’);?>: <input type=”text” name=”fullimage_width” value=”640″ /></div>

分类: 技术 标签: