<tfoot id='rMJ35'></tfoot>

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

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

    1. <legend id='rMJ35'><style id='rMJ35'><dir id='rMJ35'><q id='rMJ35'></q></dir></style></legend>

    2. PHP/GD,如何将一个圆圈从一个图像复制到另一个图像?

      时间:2024-05-11
    3. <legend id='VyPuN'><style id='VyPuN'><dir id='VyPuN'><q id='VyPuN'></q></dir></style></legend>

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

        <tbody id='VyPuN'></tbody>

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

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

                本文介绍了PHP/GD,如何将一个圆圈从一个图像复制到另一个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否有一种相当简单的方法可以将圆形区域从一个图像资源复制到另一个图像资源?imagecopymerge 之类的东西,除了圆形或椭圆形等?
                如果可能的话,我想避免使用预先创建的图像文件(任何椭圆形都可以),如果涉及透明颜色,它们自然应该单独保留图像的其余部分.

                Is there a reasonably straightforward way to copy a circular area from one image resource to another? Something like imagecopymerge except with circles or ovals etc?
                If possible, I want to avoid having to use pre-created image files (any oval shape should be possible), and if there's transparency colours involved they should naturally leave the rest of the image alone.

                我问的原因是,我有一些类允许在图像的选定区域"内应用图像操作,其工作原理是首先从图像的副本中删除该区域,然后将副本覆盖回去原本的.但是,如果您想选择一个矩形,然后在该矩形内取消选择一个圆形,并且操作只影响剩下的区域怎么办?

                Reason I'm asking, I have a few classes that allow to apply image operations inside a "selected area" of an image, which works by first deleting that area from a copy of the image, then overlaying the copy back on the original. But what if you want to select a rectangle, and then inside that deselect a circle, and have the operations only affect the area that's left?

                推荐答案

                你可以试试这个:

                1. 从原始图像开始 - $img
                2. 将该图像复制到 png - $copy
                3. 在圆形/椭圆中创建所需区域的蒙版 png 图像(带有黑色形状的magicpink"图像,黑色设置为 alpha 透明度的颜色) - $mask
                4. 将 $mask 复制到 $copy 的顶部,保持 Alpha 透明度
                5. 在 $copy 上更改您需要的内容
                6. 将 $copy 复制回 $img 以保持 Alpha 透明度

                
                    // 1. Start with the original image  
                    $img = imagecreatefromjpeg("./original.jpg");  
                    $img_magicpink = imagecolorallocatealpha($img, 255, 0, 255, 127);  
                    //imagecolortransparent($img, $img_magicpink);  
                
                    // (Get its dimensions for copying)  
                    list($w, $h) = getimagesize("./original.jpg");  
                
                    // 2. Create the first copy  
                    $copy = imagecreatefromjpeg("./original.jpg");  
                    imagealphablending($copy, true);  
                
                    $copy_magicpink = imagecolorallocate($copy, 255, 0, 255);  
                    imagecolortransparent($copy, $copy_magicpink);  
                
                    // 3. Create the mask  
                    $mask = imagecreatetruecolor($w, $h);  
                    imagealphablending($mask, true);  
                
                    // 3-1. Set the masking colours  
                    $mask_black = imagecolorallocate($mask, 0, 0, 0);  
                    $mask_magicpink = imagecolorallocate($mask, 255, 0, 255);  
                    imagecolortransparent($mask, $mask_black);  
                    imagefill($mask, 0, 0, $mask_magicpink);  
                
                    // 3-2. Draw the circle for the mask  
                    $circle_x = $w/2;  
                    $circle_y = $h/2;  
                    $circle_w = 150;  
                    $circle_h = 150;  
                    imagefilledellipse($mask, $circle_x, $circle_y, $circle_w, $circle_h, $mask_black);  
                
                    // 4. Copy the mask over the top of the copied image, and apply the mask as an alpha layer  
                    imagecopymerge($copy, $mask, 0, 0, 0, 0, $w, $h, 100);  
                
                
                    // 5. Do what you need to do to the image area  
                    // My example is turning the original image gray and leaving the masked area as colour  
                    $x = imagesx($img);  
                    $y = imagesy($img);  
                    $gray = imagecreatetruecolor($x, $y);  
                    imagecolorallocate($gray, 0, 0, 0);  
                    for ($i = 0; $i > 16) & 0xFF;  
                        $g = ($rgb >> 8) & 0xFF;  
                        $b = $rgb & 0xFF;  
                         //for gray mode $r = $g = $b  
                        $color = max(array($r, $g, $b));  
                        $gray_color = imagecolorexact($img, $color, $color,   $color);  
                        imagesetpixel($gray, $i, $j, $gray_color);  
                      }  
                    }  
                
                    // 6. Merge the copy with the origianl - maintaining alpha  
                    imagecopymergegray($gray, $copy, 0, 0, 0, 0, $w, $h, 100);  
                    imagealphablending($gray, true);  
                    imagecolortransparent($gray, $mask_magicpink);  
                
                    header('Content-Type: image/png');  
                    imagepng($gray);  
                    imagedestroy($gray);  
                

                这篇关于PHP/GD,如何将一个圆圈从一个图像复制到另一个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 MySQL 数据库中将整数的前导零存储为 INTEGER 下一篇:围绕其中心点/轴旋转 3D 形状

                相关文章

                <tfoot id='9NbZm'></tfoot>
                  <bdo id='9NbZm'></bdo><ul id='9NbZm'></ul>
              • <legend id='9NbZm'><style id='9NbZm'><dir id='9NbZm'><q id='9NbZm'></q></dir></style></legend>

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

                  1. <small id='9NbZm'></small><noframes id='9NbZm'>