如何根据数据库字段值在类中添加新值?

发布于 2024-11-19 08:58:24 字数 2368 浏览 3 评论 0原文

这就是我想做的。我创建了一个类,但我只希望该类的某些部分显示数据库中设置的某些值。该类的作用是为基本图像着色,然后将另一个图像放在上面。有时,虽然数据库中设置了多个层,所以类必须进行调整以适应。

有人知道如何做到这一点或对我如何做到这一点提出任何建议吗?

例如,此类允许对基本图像进行着色,而将另一个图像进行缩放并放置在顶部:

public function layers2 ($target, $art, $newcopy, $red, $blue, $green) {

    $artLayer = imagecreatefrompng($art); // Art Layer  
    $base = imagecreatefrompng($target); // Base Product
    $base_location = "base";

    $img = imagecreatefrompng($base);

    $width3 = imagesx( $artLayer ); // artLayer
    $height3 = imagesy( $artLayer ); // artLayer

    //COLOR THE IMAGE
    imagefilter($base, IMG_FILTER_COLORIZE, $red, $green, $blue, 1); //the product

    imagecopyresampled($base,$artLayer,350, 150, 0, 0, 300, 300, imagesx( $artLayer ), imagesy( $artLayer ));       // rotate image 

    // save the alpha
    imagesavealpha($base,true);
    // Output final product
    imagepng($base, $newcopy); //OUTPUT IMAGE

}

我想要根据数据库表中设置的基本图像的层数添加另一个值。这是因为有些图像具有不止一层颜色。

所以像这样:

public function layer_3($target, $NEWLAYER, $art, $newcopy, $r, $b, $g) {

    $artLayer = imagecreatefrompng($art); // Art Layer      
    $colorLayer1 = imagecreatefrompng($NEWLAYER); // NEW LAYER      
    $base = imagecreatefrompng($target); // Base Product
    $base_location = "base";

    $img = imagecreatefrompng($base);

    // NEW LAYER
    $width = imagesx( $colorLayer1 ); // colorLayer1
    $height = imagesy( $colorLayer1 ); // colorLayer1

    $width3 = imagesx( $artLayer ); // artLayer
    $height3 = imagesy( $artLayer ); // artLayer

    $img=imagecreatetruecolor( $width, $height ); // NEW LAYER

    imagealphablending($img, true); // NEW LAYER


    $transparent = imagecolorallocatealpha( $img, 0, 0, 0, 127 );
    imagefill( $img, 0, 0, $transparent );

    //COLOR THE IMAGE
    imagefilter($base, IMG_FILTER_COLORIZE, $r, $b, $g, 1); //the base  
    imagecopyresampled($img,$base,1,1,0,0, 1000, 1000, imagesx( $base ), imagesy( $base ) );            
    imagecopyresampled($img,$colorLayer1,1,1,0,0, 1000, 1000, imagesx( $colorLayer1 ), imagesy( $colorLayer1 )); //NEW LAYER    
    imagecopyresampled($img,$artLayer,300, 200, 0, 0, 350, 350, imagesx( $artLayer ), imagesy( $artLayer ));


    imagealphablending($img, false);
    imagesavealpha($img,true);
    imagepng($img, $newcopy);

}

Here is what I want to do. I have a class that I have created but I only want the certain parts of the class to show IF certain values are set in the database. What the class does is that it colors the base image and then places another image on top. Sometimes though there are multiple layers set in the database so the class has to adjust to accommodate.

DOES anyone know how or make any suggestions on how I can do this??

SO for example this class allow a base image to be colored and another to be scaled and placed on top:

public function layers2 ($target, $art, $newcopy, $red, $blue, $green) {

    $artLayer = imagecreatefrompng($art); // Art Layer  
    $base = imagecreatefrompng($target); // Base Product
    $base_location = "base";

    $img = imagecreatefrompng($base);

    $width3 = imagesx( $artLayer ); // artLayer
    $height3 = imagesy( $artLayer ); // artLayer

    //COLOR THE IMAGE
    imagefilter($base, IMG_FILTER_COLORIZE, $red, $green, $blue, 1); //the product

    imagecopyresampled($base,$artLayer,350, 150, 0, 0, 300, 300, imagesx( $artLayer ), imagesy( $artLayer ));       // rotate image 

    // save the alpha
    imagesavealpha($base,true);
    // Output final product
    imagepng($base, $newcopy); //OUTPUT IMAGE

}

What I want to do add another value depending on the number of layers for the base image that is set in a database table. This is because there are images that have more than one layer of color.

so something like this:

public function layer_3($target, $NEWLAYER, $art, $newcopy, $r, $b, $g) {

    $artLayer = imagecreatefrompng($art); // Art Layer      
    $colorLayer1 = imagecreatefrompng($NEWLAYER); // NEW LAYER      
    $base = imagecreatefrompng($target); // Base Product
    $base_location = "base";

    $img = imagecreatefrompng($base);

    // NEW LAYER
    $width = imagesx( $colorLayer1 ); // colorLayer1
    $height = imagesy( $colorLayer1 ); // colorLayer1

    $width3 = imagesx( $artLayer ); // artLayer
    $height3 = imagesy( $artLayer ); // artLayer

    $img=imagecreatetruecolor( $width, $height ); // NEW LAYER

    imagealphablending($img, true); // NEW LAYER


    $transparent = imagecolorallocatealpha( $img, 0, 0, 0, 127 );
    imagefill( $img, 0, 0, $transparent );

    //COLOR THE IMAGE
    imagefilter($base, IMG_FILTER_COLORIZE, $r, $b, $g, 1); //the base  
    imagecopyresampled($img,$base,1,1,0,0, 1000, 1000, imagesx( $base ), imagesy( $base ) );            
    imagecopyresampled($img,$colorLayer1,1,1,0,0, 1000, 1000, imagesx( $colorLayer1 ), imagesy( $colorLayer1 )); //NEW LAYER    
    imagecopyresampled($img,$artLayer,300, 200, 0, 0, 350, 350, imagesx( $artLayer ), imagesy( $artLayer ));


    imagealphablending($img, false);
    imagesavealpha($img,true);
    imagepng($img, $newcopy);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心 2024-11-26 08:58:24

据我所知,最简单的方法是使用层数组作为参数,因此方法签名将是:

public function my_layers_func($target, $NEWLAYERS = array(), $art, $newcopy, $r, $b, $g) 

在 my_layers_func 的主体中,您应该迭代 $NEWLAYERS 数组,应用与 $ 相同的转换Layer_3 函数中的 NEWLAYER。

这是如何重构函数的示例:

public function my_layers_func($target, $newlayers = array(), $art, $newcopy, $r, $b, $g)
        $artLayer = imagecreatefrompng($art); // Art Layer   
    $colorLayers = array();
    foreach($newlayers as $newlayer){
        $colorLayers[] = imagecreatefrompng($newlayer); // NEW LAYER      
    }
        ....

如果您需要更多解释,请告诉我!

As far I can see, the simplest way would be to use an array of layers as parameters, so the method signature will be:

public function my_layers_func($target, $NEWLAYERS = array(), $art, $newcopy, $r, $b, $g) 

And in your my_layers_func's body, you should iterate on the $NEWLAYERS array applying the same transformations as you did on $NEWLAYER in layer_3 function.

This is a sample of how you could refactor your function:

public function my_layers_func($target, $newlayers = array(), $art, $newcopy, $r, $b, $g)
        $artLayer = imagecreatefrompng($art); // Art Layer   
    $colorLayers = array();
    foreach($newlayers as $newlayer){
        $colorLayers[] = imagecreatefrompng($newlayer); // NEW LAYER      
    }
        ....

Let me know if you need more explanations!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文