有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″ />
<?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″ />
<?php echo $VM_LANG->_(‘PHPSHOP_PRODUCT_FORM_WIDTH’);?>: <input type=”text” name=”fullimage_width” value=”640″ /></div>
7 评论
嗯嗯,感謝你的回覆^^
目前没有这方面的资料哦
使用者上傳圖片時並不會去考慮到圖片比例
這正是我頭痛的地方
另外有想到用CSS給小圖固定底圖
不知道這個方法如何?
有勾選跟沒勾選都測試過
小圖顯示出來還是大小不一
例如:
A圖顯示120 X 80
B圖顯示80 X 120
我希望是都固定在 120 X 80
圖片有點擠壓也無訪
好像是这样的,但是没有完全测试:
要保证原始图片的比例必须和你在后台设置的长宽比例相同,
例如,要想显示出120×80的小图,那么原始图形的长宽要保证是3:2,这样就没有问题了;
否则,小图会根据原始图的最长的边来生成.
你好,想請教你如何固定商品小圖的寬高?
因為後台設定的縮圖寬度和高度
結果小圖顯示出來大小不一
前台看小圖會顯的很奇怪
一般只要在VirtueMart->Admin->Configuration->Site下的”Enable Dynamic Thumbnail Resizing?”打勾就可以自动生成了.