为了账号安全,请及时绑定邮箱和手机立即绑定

我正在尝试在 php 手册中实现用户提供的示例代码,但它没有按预期运行

我正在尝试在 php 手册中实现用户提供的示例代码,但它没有按预期运行

PHP
慕盖茨4494581 2021-09-18 19:35:42
我正在尝试在 PHP 手册的这个页面上实现由 kill_wombles0000(8 年前)提供的代码:https ://www.php.net/manual/en/function.imagecopymerge.php 麻烦是有错误/意外代码中的行为(例如, $a 未定义)它有点工作,但是镜像图像淡化为白色,我希望它淡化为黑色。当我做出我认为需要的改变时,我无法按照我的意愿去做。代码中有太多对我来说是新的图像函数,我无法将它们一起工作。我花了一整天的时间阅读每个函数,试图通过代码逻辑地工作,注释掉部分,改变透明度颜色,并且通常紧抓着稻草。我认为将 255,255,255 随处更改为 0,0,0 会使镜像图像淡化为黑色。我多么天真;)这是用户在 PHP 手册的该页面上提供的代码:$in = imagecreatefromjpeg('C:\test.jpg');$reflection_strength = 120;        //    starting transparency (0-127, 0 being opaque)$reflection_height = 40;        //     height of reflection in pixels$gap = 10;                        //    gap between image and reflection$orig_height = imagesy($in);                                //    store height of original image$orig_width = imagesx($in);                                    //    store height of original image$output_height = $orig_height + $reflection_height + $gap;    //    calculate height of output image// create new image to use for output. fill with transparency. ALPHA BLENDING MUST BE FALSE$out = imagecreatetruecolor($orig_width, $output_height);imagealphablending($out, false);$bg = imagecolortransparent($out, imagecolorallocatealpha($out, 255, 255, 255, 127));imagefill($out, 0, 0, $bg);imagefilledrectangle($out, 0, 0, imagesx($in), imagesy($in), $bg1);// copy original image onto new one, leaving space underneath for reflection and 'gap'imagecopyresampled ( $out , $in , 0, 0, 0, 0, imagesx($in), imagesy($in), imagesx($in), imagesy($in)); // create new single-line image to act as buffer while applying transparency$reflection_section = imagecreatetruecolor(imagesx($in), 1);imagealphablending($reflection_section, false);$bg1 = imagecolortransparent($reflection_section, imagecolorallocatealpha($reflection_section, 255, 255, 255, 127));imagefill($reflection_section, 0, 0, $bg1);在循环进入之前将 $a 设置为 0 可消除错误。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 145 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信