downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagesetthickness> <imagesetpixel
[edit] Last updated: Fri, 23 Mar 2012

view this page in

imagesetstyle

(PHP 4 >= 4.0.6, PHP 5)

imagesetstyleÇizgi tarzını ayarlar

Açıklama

bool imagesetstyle ( resource $resim , array $tarz )

imagesetstyle() işlevi imageline() ve imagepolygon() gibi çizgi çizme işlevleri tarafından özel IMG_COLOR_STYLED veya IMG_COLOR_STYLEDBRUSHED renkli çizgiler çizmek için kullanılan çizgi tarzlarını ayarlamakta kullanılır.

Değiştirgeler

resim

imagecreatetruecolor() gibi bir resim oluşturma işlevinden dönen bir resim verisi.

tarz

Piksel renklerinden oluşan bir dizi. Şeffaf bir piksel eklemek için IMG_COLOR_TRANSPARENT sabitini kullanabilirsiniz.

Dönen Değerler

Başarı durumunda TRUE, başarısızlık durumunda FALSE döner.

Örnekler

Aşağıdaki betik örneğinde bir tuvalin sol üst köşesinden sağ alt köşesine kesikli çizgi çizilmektedir:

Örnek 1 - imagesetstyle() örneği

<?php
header
("Content-type: image/jpeg");
$im  imagecreatetruecolor(100100);
$b   imagecolorallocate($im255255255);
$k imagecolorallocate($im25500);

/* 5 kırmızı 5 beyaz piksellik kesikli bir çizgi çizelim */
$style = array($k$k$k$k$k$b$b$b$b$b);
imagesetstyle($im$style);
imageline($im00100100IMG_COLOR_STYLED);

/* imagesetbrush ile imagesetstyle kullanarak
   mutlu yüzlerden bir çizgi çizelim */
$style = array($b$b$b$b$b$b$b$b$b$b$b$b$k);
imagesetstyle($im$style);

$brush imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.png");
$b2 imagecolorallocate($brush255255255);
imagecolortransparent($brush$b2);
imagesetbrush($im$brush);
imageline($im10000100IMG_COLOR_STYLEDBRUSHED);

imagejpeg($im);
imagedestroy($im);
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

imagesetstyle.jpg

Ayrıca Bakınız



imagesetthickness> <imagesetpixel
[edit] Last updated: Fri, 23 Mar 2012
 
add a note add a note User Contributed Notes imagesetstyle
php at imperium dot be 06-Aug-2010 01:05
Be aware that styles are applied towards the width of the line instead of linear.
To convert a style to be used for thick lines you can use the function below:

<?php
/*
ImageStyleThicken(<aStyle>,<iThickness>) --> <aThickStyle>

<aStyle> is the style array for a thickness of 1 (see imagesetstyle()).
<iThickness> is the new thickness to apply (see imagesetthickness()).

<aThickStyle> is the style array suitable for the given thickness.
*/
function ImageStyleThicken($_1,$_2) {
   
$a = array();
    foreach (
$_1 as $x) {
       
$i = $_2;
        do
$a[] = $x; while (--$i>0); }
    return
$a;
}
?>
Wander 13-Dec-2007 04:12
Function to make a line with random fading:

<?php
   
function fading_line($img,$sx,$sy,$ex,$ey){
       
$r=rand(0,5);$g=rand(0,5);$b=rand(0,5);
       
$l=sqrt((($ex-$sx)*($ex-$sx))+(($ey-$sy)*($ey-$sy)));
        for(
$i=0;$i<$l;$i++){
           
$a = array(255-((255/$l)*$i), 255,0,(255/$l)*$i/2,(255/$l)*$i,(255-((255/$l)*$i))/2);
           
$style[]=imagecolorallocate($img,$a[$r],$a[$g],$a[$b]);
        }
       
imagesetstyle($img,$style);
       
imageline($img,$sx,$sy,$ex,$ey,IMG_COLOR_STYLED);
    }
   
   
fading_line($img,10,20,490,40);    // image, start x, start y, end x, end y
?>
Michael_Todd_335 at yahoo dot com 27-Jun-2007 03:40
Watch out! If you pass imagesetstyle() an empty array as the second argument, it will crash your server!
I was messing with it just earlier and accidentally did so, and the page took a good minute to process, when my Apache server came up with the good ol' Windows 'Send Error Report' window.
Cruz at FtUC dot net 14-Jan-2006 08:45
When lines drawn with imagesetstyle seem to produce a thin white line only, make sure antialiasing is disabled.

<?
  imageantialias($im, false);
  $style = array($gridxcolor, $gridxcolor, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
  imagesetstyle($im, $style);
  imageline($im, $x, 0, $x, $ymax+5, IMG_COLOR_STYLED);
  imageantialias($im, true);
?>

Setstyle and Antialias don't go together.
zackbloom at gmail dot com 06-Dec-2005 07:44
Use this to set the style to any combination of pixels.
You can pass as many modifiers as you wish.
Use the format [num]r[red]g[green]b[blue].

For example:

$im=dashed($im,"4r255g0b0","2r0g255b0","5r0g0b255");
imageline($im, 0, 0, 600, 600, IMG_COLOR_STYLED);

function dashed($im){
$size = func_num_args();
for($i = 0; $i < $size; $i++){
$arg = func_get_arg($i);
if(!is_resource($arg)){
$r=substr($arg,strpos($arg,"r")+1,
strpos($arg,"g")-strpos($arg,"r")-1);
$g=substr($arg,strpos($arg,"g")+1,
strpos($arg,"b")-strpos($arg,"g")-1);
$b=substr($arg,strpos($arg,"b")+1,
strlen($arg)-strpos($arg,"b"));
$color = imagecolorallocate($im,$r,$g,$b);
$x = substr($arg,0,strpos($arg,"r"));
$vals[$i] = array_fill(0,$x,$color);
}
}
for($k=0;$k<count($vals)+1;$k++)
if(array_key_exists($k,$vals)) $prop=array_merge($prop,$vals[$k]);
imagesetstyle($im, $prop);
return $im;
}
yhoko at yhoko dot com 11-Aug-2004 12:24
When drawing lines that are >1px thick you'll have to setup the array corresponding to this fact (since there's no multi-array support for this function).

For example if the line's 3 pixels thick each 2nd color goes to the 2nd line, each 3rd color to the 3rd line and so on.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites