简体   繁体   中英

php creating image

I am creating image with php function imagesetpixel() there I could set starting x position and y position, but if I have it in code:

for ($i=1;$i<50;$i++)
{ 
    for ($a=1;$a<50;$a++)
    { 
         imagesetpixel($img, $i, $a, $color); 
    } 
}

this create every field 1x1px but I want it maybe 5x5px. is it possible to make something like it?

see below url:-

http://phptutorial.info/?imagesetpixel

http://php.net/manual/en/function.imagesetpixel.php

example:-

<?php

$x = 200;
$y = 200;

$gd = imagecreatetruecolor($x, $y);

$corners[0] = array('x' => 100, 'y' =>  10);
$corners[1] = array('x' =>   0, 'y' => 190);
$corners[2] = array('x' => 200, 'y' => 190);

$red = imagecolorallocate($gd, 255, 0, 0); 

for ($i = 0; $i < 100000; $i++) {
  imagesetpixel($gd, round($x),round($y), $red);
  $a = rand(0, 2);
  $x = ($x + $corners[$a]['x']) / 2;
  $y = ($y + $corners[$a]['y']) / 2;
}

header('Content-Type: image/png');
imagepng($gd);

?>

The size of your image you have to pass as arguments to the - for instance [imagecreate][1] function.

Example:

$width = 5;
$height = 5;

$img = imagecreate($width, $height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM