Ben nesneleri (görüntü, metin veya dikdörtgen) bir dizi var ve ben onlardan bir görüntü oluşturmak için çalışıyorum. Ama bu öğelerden birini eklemeye zaman, önceki elemanları sildi olsun gibi geliyor bana. İşte benim kod:
if(isset($_GET['elements'])){
$elements = json_decode(stripslashes($_GET['elements']));
$gfx = imagecreate(160,120);
$width = 160;
$height = 120;
$white = imagecolorallocate($gfx, 255, 255, 255);
$id = $_GET['id'];
$username=$_GET['username'];
$name=$_GET['name'];
foreach ($elements as $element){
$type = $element->type;
switch($type){
case 'textBox':
text_thumb( $element,$gfx);
break;
case 'image':
image_thumb( $element,$gfx,$name,$username);
break;
case 'rectangle':
box_thumb( $element,$gfx);
break;
}
}
header('Content-type: image/png');
imagepng($gfx,'../thumbnail/'.$username.'_'.$name.'_'.$id.'.png');
}
function text_thumb ($element,$gfx){
function wrap($fontSize, $angle, $fontFace, $string, $width){
$ret = "";
$arr = explode(' ', $string);
foreach ( $arr as $word ){
$teststring = $ret.' '.$word;
$testbox = imagettfbbox($fontSize, $angle, $fontFace, $teststring);
if ( $testbox[4]-$testbox[0] > $width ){
$ret.=($ret==""?"":"\n").$word;
} else {
$ret.=($ret==""?"":' ').$word;
}
}
return $ret;
}
$width = $element->width/5;
$left =$element->left/5;
$top =$element->top/5;
$string = $element->text;
$fontsize = 2.4;
$font = "../fonts/arial.TTF";
$fonth = imagefontheight($fontsize);
$text = wrap($fontsize, 0, $font, $string, $width);
imagettftext($gfx,$fontsize,0,$left,$top,$black,$font,$text);
}
function box_thumb ($element,$gfx){
$width = $element->width/5;
$height = $element->height/5;
$left =$element->left/5;
$top =$element->top/5;
$x2=$left+$width;
$y2=$top+$height;
$black = imagecolorallocate($gfx, 0, 0, 0);
imagefilledrectangle($gfx,$left, $top,$x2,$y2,$black);
}
function image_thumb ($element,$gfx,$name,$username){
$height = $element->height;
$width = $element->width;
$left =$element->left/5;
$top =$element->top/5;
$src =$element->src;
$extype = explode(".", $src);
$type=$extype[1];
if($type=="jpg"||$type=="JPG")$type="jpeg";
$creat="imagecreatefrom".$type;
$insert=$creat("../user_pics/view/{$username}_{$name}_{$src}");
imagecopyresampled($gfx, $insert, $left, $top, 0, 0, $width/5, $height/5, $width, $height);
}
Bu kod, webservice olarak kullanılır, burada $ elemanları dizinin bir örneği aşağıda verilmiştir:
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] => stdClass Object
(
[src] => 019.png
[id] => 7
[type] => image
[width] => 635
[height] => 205
[top] => 395
[left] => 84
[page] => 2
)
[8] => stdClass Object
(
[type] => rectangle
[top] => 33
[left] => 90
[page] => 2
[width] => 602
[height] => 128
[id] => 8
)
[9] => stdClass Object
(
[type] => textBox
[top] => 182
[left] => 171
[page] => 2
[width] => 539
[height] => 154
[id] => 9
[text] => SINA
)
)
Ben görüntüde elemanlarının değişken bir dizi olduğunu düşünüyor, imagecopymerge kullanın veya herhangi kolay yolu var gerekiyor?
*** GÜNCELLEME:
Ben dizide birden fazla resim varsa parçası, yani sadece ayrıca kutusundan oluşturmak ve gayet iyi çalışıyor metin, ve, bu yüzden, doğru hepsini içerir: Ben ... "case 'image'" çıkarırsanız düşündüm çünkü "imagecopyresampled" içinde olabilir?