lightinthebox ZenCart里调节 设置产品图片大小的方法及其算法

如果要修改ZenCart产品显示图片的大小,可以通过Admin->Configure->Image来修改显示图片的参数,而参数的变量名则表示了该变量所起的作用,很好理解。下面就简单介绍一下main页面常用的几个变量的含义:

1) 如果需要修改Monthly Specials的图片大小,则调整这两个参数即可:
Small Image Width
Small Image Height


2) 如果需要调整Product Info页面里的图片,则调整这两个参数即可:
Product Info - Image Width
Product Info - Image Height

3) 如果需要调整Product New Listing的图片大小 ,则调整这两个参数即可:
Image - New Products Width
Image - New Products Height

其他参数的意思很好理解,反正多试一试就知道了。

当你把Calculate Image Size选为True的时候,ZenCart会根据它的算法来调整图片的大小,否则严格地按照你所规定的Width和Height来显示图片。

ZenCart调整图片的算法:

通过这些变量设置的值,均是放大或缩小图片后显示的最大值,ZenCart会根据你的图片实际比例来调整好显示效果的,所以,你不用担心你的图片会变形。ZenCart按你给定的长宽值,等比例缩放要显示图片的长和宽,ZenCart会选Width、Height最先达到预设值的比例,来决定整个图片的缩放比例。总之,ZenCart就是以不超过你的预设值为原则来缩放图片的。

  
        if (!copy($destination_name, $destination_name_large)) {
          $messageStack->add('failed to copy '.$destination_name_large.'...', "error" );
        }else{
          $messageStack->add('Successed to copy '.$destination_name_large.'...', "success" );
          if ($data['ImgExtension'] == ".jpg" || $data['ImgExtension'] == ".jpeg")
            $im = @imagecreatefromjpeg ($destination_name_large );
          if ($data['ImgExtension'] == ".gif")
            $im = @imagecreatefromgif ($destination_name_large );
          if ($data['ImgExtension'] == ".png")
            $im = @imagecreatefrompng ($destination_name_large );
          list($width_orig, $height_orig) = getimagesize($destination_name_large );
          $width = PRODUCT_MEDIUM_LARGE_WIDTH;
          $height = PRODUCT_MEDIUM_LARGE_HEIGHT;
          if ($width && ($width_orig < $height_orig)) {
              $width = ($height / $height_orig) * $width_orig;
          } else {
              $height = ($width / $width_orig) * $height_orig;
          }
          $im_s = @imagecreatetruecolor ( PRODUCT_MEDIUM_LARGE_WIDTH, PRODUCT_MEDIUM_LARGE_HEIGHT );
          $white = imagecolorallocate($im_s, 255, 255, 255);
          imagefill($im_s, 0, 0, $white);
          if ($width_orig <= $width){
           $wpos=(PRODUCT_MEDIUM_LARGE_WIDTH - $width_orig)/2;
           $hpos=(PRODUCT_MEDIUM_LARGE_HEIGHT - $height_orig)/2;
           imagecopy($im_s,$im,$wpos, $hpos, 0, 0,$width_orig,$height_orig );
          }else{
           $wpos=(PRODUCT_MEDIUM_LARGE_WIDTH - $width)/2;
            $hpos=(PRODUCT_MEDIUM_LARGE_HEIGHT - $height)/2;
   //imagecopyresized($im_s,$im,$wpos, $hpos, 0, 0,$width,$height,$width_orig,$height_orig );
            imagecopyresampled($im_s,$im,$wpos, $hpos, 0, 0,$width,$height,$width_orig,$height_orig );
          }
          $im_watermark = @imagecreatefrompng ($watermark );
          list($water_w, $water_h) = getimagesize($watermark);
          $dst_x = (PRODUCT_MEDIUM_LARGE_WIDTH - $water_w)/2;
          $dst_y = (PRODUCT_MEDIUM_LARGE_HEIGHT - $water_h)/2;
          imagecopymerge($im_s, $im_watermark, $dst_x, $dst_y, 0, 0,$water_w, $water_h,$wateralpha);
          @imagejpeg ( $im_s, $destination_name_large, 100 );
          @imagedestroy ( $im );       
        }
       
        if ($data['ImgExtension'] == ".jpg" || $data['ImgExtension'] == ".jpeg")
          $im = @imagecreatefromjpeg ($destination_name_small );
        if ($data['ImgExtension'] == ".gif")
          $im = @imagecreatefromgif ($destination_name_small );
        if ($data['ImgExtension'] == ".png")
          $im = @imagecreatefrompng ($destination_name_small );
        list($width_orig, $height_orig) = getimagesize($destination_name_small);
        $width = PRODUCT_MEDIUM_SMALL_WIDTH;
        $height = PRODUCT_MEDIUM_SMALL_HEIGHT;
        if ($width && ($width_orig < $height_orig)) {
            $width = ($height / $height_orig) * $width_orig;
        } else {
            $height = ($width / $width_orig) * $height_orig;
        }
        $im_s = @imagecreatetruecolor( PRODUCT_MEDIUM_SMALL_WIDTH, PRODUCT_MEDIUM_SMALL_HEIGHT ) or die("Cannot Initialize new GD image stream");
        $white = imagecolorallocate($im_s, 255, 255, 255);
        imagefill($im_s, 0, 0, $white);
        if ($width_orig <= $width){
            $wpos=(PRODUCT_MEDIUM_SMALL_WIDTH - $width_orig)/2;
            $hpos=(PRODUCT_MEDIUM_SMALL_HEIGHT - $height_orig)/2;
            imagecopy($im_s,$im,$wpos, $hpos, 0, 0,$width_orig,$height_orig );
        }else{
            $wpos=(PRODUCT_MEDIUM_SMALL_WIDTH - $width)/2;
            $hpos=(PRODUCT_MEDIUM_SMALL_HEIGHT - $height)/2;
            imagecopyresampled($im_s,$im,$wpos, $hpos, 0, 0,$width,$height,$width_orig,$height_orig );
        }
        imagejpeg ( $im_s, $destination_name_small, 100 );
       
        imagedestroy ( $im );
        $products_image_names[] = 's/'.$nameBase.$data['ImgExtension'];
       
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值