2010-06-14 82 views
0

我想通过复制背景并将其向下移动1个像素和右侧1个像素,采用矩形PNG并使用GD添加深度。我也尝试保留透明背景。使用GD和PHP的PNG组合

我在保存透明度方面遇到了一堆麻烦。

任何帮助将不胜感激。

谢谢!

$obj = imagecreatefrompng('rectangle.png'); 
    $depth = 5; 
    $obj_width = imagesx($obj); 
    $obj_height = imagesy($obj); 
    imagesavealpha($obj, true); 
     for($i=1;$i<=$depth;$i++){ 
      $layer = imagecreatefrompng('rectangle.png'); 
      imagealphablending($layer, false); 
      imagesavealpha($layer, true); 

      $new_obj = imagecreatetruecolor($obj_width+$i,$obj_height+$i); 
      $new_obj_width = imagesx($new_obj); 
      $new_obj_height = imagesy($new_obj); 
      imagealphablending($new_obj, false); 
      imagesavealpha($new_obj, true); 

      $trans_color = imagecolorallocatealpha($new_obj, 0, 0, 0, 127); 
      imagefill($new_obj, 0, 0, $trans_color); 

      imagecopyresampled($new_obj, $layer, $i, $i, 0, 0, $obj_width, $obj_height, $obj_width, $obj_height); 
      //imagesavealpha($new_obj, true); 
      //imagesavealpha($obj, true); 
     } 
    header ("Content-type: image/png"); 
    imagepng($new_obj); 
    imagedestroy($new_obj); 
+0

你试过了什么代码? – artlung 2010-06-14 21:23:38

+3

可能有用:http://stackoverflow.com/questions/32243/can-png-image-transparency-be-preserved-when-using-phps-gdlib-imagecopyresampled – artlung 2010-06-14 21:24:26

+0

我已经在上面添加了我的当前代码。 – Dominic 2010-06-14 22:18:13

回答