[英]How to resize png and gif image and store transparent background using php?
[英]How to merge transparent PNG with image using PHP?
情况是这样的:我有一个50x50的小图片。 我还有一个小的50x50透明图片,其中包含50x50 pic的帧,所以我基本上想把透明的png 放在图像的顶部并合并这两个,这将导致最终的第三张图片看起来像这样: http ://img245.imageshack.us/i/50x50n.png
注意:我不想仅使用HTML(我通过编写一个将透明png放在原始图像顶部的javascript插件来实现这一点)。
谢谢。
您可以使用PHP GD2库将两个图像合并在一起。
例:
<?php
# If you don't know the type of image you are using as your originals.
$image = imagecreatefromstring(file_get_contents($your_original_image));
$frame = imagecreatefromstring(file_get_contents($your_frame_image));
# If you know your originals are of type PNG.
$image = imagecreatefrompng($your_original_image);
$frame = imagecreatefrompng($your_frame_image);
imagecopymerge($image, $frame, 0, 0, 0, 0, 50, 50, 100);
# Save the image to a file
imagepng($image, '/path/to/save/image.png');
# Output straight to the browser.
imagepng($image);
?>
添加imagealphablending($frame,true);
在imagecopymerge()
之前,如果你想在图像上保持PNG帧透明度。
你可以使用ImageMagick :: Composite来做到这一点。 第一个用户贡献的注释应该足以掌握这个概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.