{"id":1201,"date":"2010-09-08T18:31:30","date_gmt":"2010-09-08T10:31:30","guid":{"rendered":"http:\/\/fanhaijun.com\/?p=1201"},"modified":"2011-03-14T22:16:16","modified_gmt":"2011-03-14T14:16:16","slug":"%e4%bf%ae%e6%94%b9virtuemart%e7%9a%84%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fanhaijun.com\/?p=1201","title":{"rendered":"\u4fee\u6539virtuemart\u7684\u56fe\u7247\u4e0a\u4f20\u529f\u80fd"},"content":{"rendered":"<p>\u67092\u4e2a\u56fe\u7247\u4e0a\u4f20\u7684\u5730\u65b9\u9700\u8981\u4fee\u6539:<\/p>\n<p>1 \u9ed8\u8ba4\u4ea7\u54c1\u7684\u5927\u56fe\uff0c\u8981\u628a\u5b83\u4fee\u6539\u4e3a\u4e0d\u7ba1\u4e0a\u4f20\u7684\u56fe\u7247\u591a\u5927\uff0c\u90fd\u4f1a\u81ea\u52a8\u66f4\u6539\u4e3a640&#215;480\u5927\u5c0f\u3002<\/p>\n<blockquote><p>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.<\/p>\n<p><strong>original code<\/strong><\/p>\n<pre>\/\/ Resize the Full Image\r\nif( !empty ( $_FILES[$tmp_field_name][\"tmp_name\"] )) {\r\n\t$full_file = $_FILES[$tmp_field_name][\"tmp_name\"];\r\n\t$image_info = getimagesize($full_file);\r\n}\r\n<\/pre>\n<p><strong>Replace with the following code<\/strong><\/p>\n<pre>\/\/ Beginning of Modify by DesignerSandbox\r\n\/\/ resize the full product image dynamically and give it maximal dimensions 600x600 during uploading\r\n\/\/ Resize the Full Image\r\nif( !empty ( $_FILES[$tmp_field_name][\"tmp_name\"] )) {\r\n\t$full_file = $_FILES[$tmp_field_name][\"tmp_name\"];\r\n\r\n\t$image_info = getimagesize($full_file);\r\n\t$original_height =  $image_info[1];\r\n\t$original_width =  $image_info[0];\r\n\r\n\tif ($original_height &gt; $original_width) {\r\n\t\t$largewidth = (480 \/ $original_height) * $original_width;\r\n\t\t$largeheight = \"480px\";\r\n\t} else {\r\n\t\t$largeheight = (640 \/ $original_width) * $original_height;\r\n\t\t$largewidth = \"640px\";\r\n\t}\r\n\r\n\t\/\/Get Image size info\r\n\tlist($original_width, $original_height, $image_type) = getimagesize($full_file);\r\n\r\n\tswitch ($image_type)\r\n\t{\r\n\t\tcase 1: $im = imagecreatefromgif($full_file); break;\r\n\t\tcase 2: $im = imagecreatefromjpeg($full_file);  break;\r\n\t\tcase 3: $im = imagecreatefrompng($full_file); break;\r\n\t\tdefault:  trigger_error('Unsupported filetype!', E_USER_WARNING);  break;\r\n\t}\r\n\r\n\t$big = imagecreatetruecolor($largewidth, $largeheight);\r\n\r\n\t\/* Check if this image is PNG or GIF, then set if Transparent*\/\r\n\tif(($image_type == 1) OR ($image_type==3))\r\n\t{\r\n\t\timagealphablending($big, false);\r\n\t\timagesavealpha($big,true);\r\n\t\t$transparent = imagecolorallocatealpha($big, 255, 255, 255, 127);\r\n\t\timagefilledrectangle($big, 0, 0, $largewidth, $largeheight, $transparent);\r\n\t}\r\n\timagecopyresampled($big, $im, 0, 0, 0, 0, $largewidth, $largeheight, $original_width, $original_height);\r\n\r\n\t\/\/Generate the file, and rename it to $newfilename\r\n\tswitch ($image_type)\r\n\t{\r\n\t\tcase 1: imagegif($big,$full_file); break;\r\n\t\tcase 2: imagejpeg($big,$full_file);  break;\r\n\t\tcase 3: imagepng($big,$full_file); break;\r\n\t\tdefault:  trigger_error('Er ging iets fout!', E_USER_WARNING);  break;\r\n\t}}\r\n\/\/ end of edit by DesignerSandbox\r\n<\/pre>\n<\/blockquote>\n<p>2 \u4e0a\u4f20\u989d\u5916\u7684\u56fe\u7247\u65f6\u5019\uff0c\u628a\u9ed8\u8ba4\u7684\u5c3a\u5bf8\u8bbe\u7f6e\u6539\u4e3a640&#215;480\uff1a<\/p>\n<p>\u6253\u5f00\uff1a\/administrator\/components\/com_virtuemart\/html\/product.file_form.php \u6587\u4ef6\uff0c<\/p>\n<p>\u628a\u4e0b\u5217\u4ee3\u7801\uff1a<\/p>\n<blockquote><p>&lt;?php echo $VM_LANG-&gt;_(&#8216;PHPSHOP_PRODUCT_FORM_HEIGHT&#8217;);?&gt;:  &lt;input type=&#8221;text&#8221; name=&#8221;fullimage_height&#8221; <span style=\"color: #ff0000;\"><strong>value=&#8221;500&#8243; <\/strong><\/span>\/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;<br \/>\n&lt;?php echo $VM_LANG-&gt;_(&#8216;PHPSHOP_PRODUCT_FORM_WIDTH&#8217;);?&gt;:  &lt;input type=&#8221;text&#8221; name=&#8221;fullimage_width&#8221; <span style=\"color: #ff0000;\"><strong>value=&#8221;500&#8243; <\/strong><\/span> \/&gt;&lt;\/div&gt;<\/p><\/blockquote>\n<p>\u6539\u4e3a\uff1a<\/p>\n<blockquote><p>&lt;?php echo $VM_LANG-&gt;_(&#8216;PHPSHOP_PRODUCT_FORM_HEIGHT&#8217;);?&gt;:  &lt;input type=&#8221;text&#8221; name=&#8221;fullimage_height&#8221; <strong><span style=\"color: #ff0000;\">value=&#8221;480&#8243;<\/span><\/strong> \/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;<br \/>\n&lt;?php echo $VM_LANG-&gt;_(&#8216;PHPSHOP_PRODUCT_FORM_WIDTH&#8217;);?&gt;:  &lt;input type=&#8221;text&#8221; name=&#8221;fullimage_width&#8221; <strong><span style=\"color: #ff0000;\">value=&#8221;640&#8243;<\/span><\/strong> \/&gt;&lt;\/div&gt;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u67092\u4e2a\u56fe\u7247\u4e0a\u4f20\u7684\u5730\u65b9\u9700\u8981\u4fee\u6539: 1 \u9ed8\u8ba4\u4ea7\u54c1\u7684\u5927\u56fe\uff0c\u8981\u628a\u5b83\u4fee&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[104],"tags":[],"class_list":["post-1201","post","type-post","status-publish","format-standard","hentry","category-technogy"],"_links":{"self":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/1201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1201"}],"version-history":[{"count":0,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/1201\/revisions"}],"wp:attachment":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}