<i id='DEWCQ'><tr id='DEWCQ'><dt id='DEWCQ'><q id='DEWCQ'><span id='DEWCQ'><b id='DEWCQ'><form id='DEWCQ'><ins id='DEWCQ'></ins><ul id='DEWCQ'></ul><sub id='DEWCQ'></sub></form><legend id='DEWCQ'></legend><bdo id='DEWCQ'><pre id='DEWCQ'><center id='DEWCQ'></center></pre></bdo></b><th id='DEWCQ'></th></span></q></dt></tr></i><div id='DEWCQ'><tfoot id='DEWCQ'></tfoot><dl id='DEWCQ'><fieldset id='DEWCQ'></fieldset></dl></div>

      1. <legend id='DEWCQ'><style id='DEWCQ'><dir id='DEWCQ'><q id='DEWCQ'></q></dir></style></legend>
      2. <tfoot id='DEWCQ'></tfoot>

        <small id='DEWCQ'></small><noframes id='DEWCQ'>

        • <bdo id='DEWCQ'></bdo><ul id='DEWCQ'></ul>

        PHP - 替换图像中的颜色

        时间:2023-05-21

              <tbody id='YzYxr'></tbody>

            <tfoot id='YzYxr'></tfoot>
              <legend id='YzYxr'><style id='YzYxr'><dir id='YzYxr'><q id='YzYxr'></q></dir></style></legend>
            • <i id='YzYxr'><tr id='YzYxr'><dt id='YzYxr'><q id='YzYxr'><span id='YzYxr'><b id='YzYxr'><form id='YzYxr'><ins id='YzYxr'></ins><ul id='YzYxr'></ul><sub id='YzYxr'></sub></form><legend id='YzYxr'></legend><bdo id='YzYxr'><pre id='YzYxr'><center id='YzYxr'></center></pre></bdo></b><th id='YzYxr'></th></span></q></dt></tr></i><div id='YzYxr'><tfoot id='YzYxr'></tfoot><dl id='YzYxr'><fieldset id='YzYxr'></fieldset></dl></div>
              • <bdo id='YzYxr'></bdo><ul id='YzYxr'></ul>

                  <small id='YzYxr'></small><noframes id='YzYxr'>

                  本文介绍了PHP - 替换图像中的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  希望有人能帮忙

                  我制作了一个屏蔽图像的脚本......但是它依赖于一种颜色来屏蔽(绿屏"样式).问题是,如果我屏蔽的图像包含那种颜色,它就会被破坏.

                  I have made a script that masks images... however it is reliant on a colour to mask with ( 'green screen' style). The trouble is if the image that I am masking contains that colour it is ruined.

                  我要做的是在屏蔽图像之前用类似的颜色(例如 0,0,254)替换任何出现的键控颜色 (0,0,255).

                  What I am looking to do is prior to masking the image replace any occurance of my keying colour (0,0,255) with a similar colour such as 0,0,254.

                  我找到了一些基于 gif 或 256 色 PNG 的解决方案,因为它们已编入索引..

                  I have found a few solutions based around gif's or 256 colour PNG as they are indexed..

                  所以我的问题也是将其转换为 gif 或 256 png 然后查看索引并替换颜色或搜索每个像素并替换颜色是否更有效.

                  So my question is also will it be more efficient to convert it to a gif or 256 png then look through the index and replace the colour or search through every pixel and replace the colours.

                  谢谢,

                  推荐答案

                  您需要打开输入文件并扫描每个像素以检查色键值.

                  You need to open the input file and scan each pixel to check for your chromokey value.

                  像这样:

                  // Open input and output image
                  $src = imagecreatefromJPEG('input.jpg') or die('Problem with source');
                  $out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die('Problem In Creating image');
                  
                  // scan image pixels
                  for ($x = 0; $x < imagesx($src); $x++) {
                      for ($y = 0; $y < imagesy($src); $y++) {
                          $src_pix = imagecolorat($src,$x,$y);
                          $src_pix_array = rgb_to_array($src_pix);
                  
                              // check for chromakey color
                              if ($src_pix_array[0] == 0 && $src_pix_array[1] == 0 && $src_pix_array[2] == 255) {
                                  $src_pix_array[2] = 254;
                              }
                  
                  
                          imagesetpixel($out, $x, $y, imagecolorallocate($out, $src_pix_array[0], $src_pix_array[1], $src_pix_array[2]));
                      }
                  }
                  
                  
                  // write $out to disc
                  
                  imagejpeg($out, 'output.jpg',100) or die('Problem saving output image');
                  imagedestroy($out);
                  
                  // split rgb to components
                  function rgb_to_array($rgb) {
                      $a[0] = ($rgb >> 16) & 0xFF;
                      $a[1] = ($rgb >> 8) & 0xFF;
                      $a[2] = $rgb & 0xFF;
                  
                      return $a;
                  }
                  

                  这篇关于PHP - 替换图像中的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将可点击的锚标签转换为 html 文档中的纯文本 下一篇:用 PHP 替换

                  相关文章

                  最新文章

                  <i id='ArtHg'><tr id='ArtHg'><dt id='ArtHg'><q id='ArtHg'><span id='ArtHg'><b id='ArtHg'><form id='ArtHg'><ins id='ArtHg'></ins><ul id='ArtHg'></ul><sub id='ArtHg'></sub></form><legend id='ArtHg'></legend><bdo id='ArtHg'><pre id='ArtHg'><center id='ArtHg'></center></pre></bdo></b><th id='ArtHg'></th></span></q></dt></tr></i><div id='ArtHg'><tfoot id='ArtHg'></tfoot><dl id='ArtHg'><fieldset id='ArtHg'></fieldset></dl></div>

                        <bdo id='ArtHg'></bdo><ul id='ArtHg'></ul>

                    1. <small id='ArtHg'></small><noframes id='ArtHg'>

                    2. <tfoot id='ArtHg'></tfoot>
                      <legend id='ArtHg'><style id='ArtHg'><dir id='ArtHg'><q id='ArtHg'></q></dir></style></legend>