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