Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php GD图像覆盖透明png_Php_Gd_Transparent - Fatal编程技术网

Php GD图像覆盖透明png

Php GD图像覆盖透明png,php,gd,transparent,Php,Gd,Transparent,我有一个透明的图像,我想覆盖在整个图像上,给它一个边界效果。在此代码中,它将裁剪现有图像。它合并了两者,但最终的顶部没有显示阿尔法。我怎样才能解决这个问题 <? $dst_x = 0; // X-coordinate of destination point. $dst_y = 0; // Y --coordinate of destination point. $src_x = 163; // Crop Start X position in ori

我有一个透明的图像,我想覆盖在整个图像上,给它一个边界效果。在此代码中,它将裁剪现有图像。它合并了两者,但最终的顶部没有显示阿尔法。我怎样才能解决这个问题

 <?
    $dst_x = 0;   // X-coordinate of destination point. 
    $dst_y = 0;   // Y --coordinate of destination point. 
    $src_x = 163; // Crop Start X position in original image
    $src_y = 0;   // Crop Srart Y position in original image
    $dst_w = 469; // Thumb width
    $dst_h = 296; // Thumb height
    $src_w = 469; // $src_x + $dst_w Crop end X position in original image
    $src_h = 296; // $src_y + $dst_h Crop end Y position in original image

    // Creating an image with true colors having thumb dimensions.( to merge with the original image )
    $dst_image = imagecreatetruecolor($dst_w,$dst_h);
    // Get original image
    $src_image = imagecreatefromjpeg("http://www.ucatholic.com/wp-content/uploads/2012/10/Sallixtus-631x295.jpg");
    // Cropping 
    imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    // Saving 
    imagejpeg($dst_image, "images/crop.jpg");

    $src = imagecreatefrompng('http://www.EdVizenor.com/images/saintCover.png');

    /// THIS LINE NOT WORKING - -   // Copy and merge
    imagecopymerge($dst_image, $src, 0, 0, 0, 0, 469, 296, 100);

    header('Content-Type: image/png');
    imagegif($dst_image);
    ?>

不要使用imagecopymerge,使用imagecopy,它将正常工作,您的水印将以alpha显示

imagecopy($dst_image, $src, 0, 0, 0, 0, 469, 296);
如果使用imagecopy而不是imagecopymerge,您将失去对alpha通道的控制

如果你想使用Gd扩展实现一个真正快速的叠加动作,我想你可以使用

如果你想知道怎么做,请看我的答案

如果需要拉丝边框,可以使用如下方式:


如何修复图像重新采样(imagecopyresampled),以匹配具有定义的高度和宽度的特定块?
use Jaguar\Canvas,
    Jaguar\Drawable\Border;

    $canvas = new Canvas('your image');
    $brush = new Canvas('style image');

    $border = new Border(20);
    $border->draw($canvas,$brush);

    $canvas->save('path to save')->show();