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);
}
非常感谢你,但我不得不承认我不太清楚如何去做你刚刚提到的事情。有没有办法可以详细说明? – GGcupie
我用一个重构的例子编辑了我的答案... –
谢谢Fabrizio! – GGcupie