如何创建透明画布,然后向其中添加透明 png?
我需要创建一个透明图像,然后将透明 png 组合到其中,同时保持图像质量。
我该怎么做?
imagecreatetruecolor(...);
//processing using imagecopymerge(..);
imagepng(...);
输出黑色背景。
谢谢:)
这是我的实际代码供参考...
$d = getimagesize(TMP.$this->files[0]);
$source_height = $d[0];
$source_width = $d[1];
$this->canvas = imagecreatetruecolor($source_width*count($this->files),$source_height);
imagealphablending($this->canvas, false );
$i=0;
foreach($this->files as $f){
$dst_x = $source_width*$i;
$im = imagecreatefrompng(TMP.$f);
imagecopyresampled ( $this->canvas , $im ,
$dst_x ,
$dst_y = 0 ,
$src_x = 0 ,
$src_y = 0 ,
$source_width ,
$source_height ,
$source_width ,
$source_height);
$i++;
imagepng($im,TMP.$i.".png");
if($i>3)break;
}
$fn = TMP."stiched_up_$i*$source_width.png";
imagesavealpha($this->canvas,TRUE);
imagepng($this->canvas,$fn);
i need to create a transparent image, then combine transparent pngs to it whilst maintaining image quality.
how can i do this?
imagecreatetruecolor(...);
//processing using imagecopymerge(..);
imagepng(...);
outputs a black background.
thanks :)
here's my actual code for reference...
$d = getimagesize(TMP.$this->files[0]);
$source_height = $d[0];
$source_width = $d[1];
$this->canvas = imagecreatetruecolor($source_width*count($this->files),$source_height);
imagealphablending($this->canvas, false );
$i=0;
foreach($this->files as $f){
$dst_x = $source_width*$i;
$im = imagecreatefrompng(TMP.$f);
imagecopyresampled ( $this->canvas , $im ,
$dst_x ,
$dst_y = 0 ,
$src_x = 0 ,
$src_y = 0 ,
$source_width ,
$source_height ,
$source_width ,
$source_height);
$i++;
imagepng($im,TMP.$i.".png");
if($i>3)break;
}
$fn = TMP."stiched_up_$i*$source_width.png";
imagesavealpha($this->canvas,TRUE);
imagepng($this->canvas,$fn);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终工作代码:
final working code: