2012-08-10 78 views
0

我創建的圖像與PHP函數imagesetpixel()那裏我可以設置起始x位置和y位置,但如果我有它的代碼:PHP創建圖像

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

此創建的每一個領域1x1px但我想它可能5x5px。有可能做出類似的東西嗎?

回答

1

見下文URL: -

http://phptutorial.info/?imagesetpixel

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

例如: -

<?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); 

?> 
+0

是的,但這也創造了太多隻有1x1px領域 – dontHaveName 2012-08-10 15:28:29

+0

我想它不可能設置它像我想要的 – dontHaveName 2012-08-10 15:31:00

0

您必須將圖像的大小作爲參數傳遞給 - 例如[imagecreate] [1]函數。

實施例:

$width = 5; 
$height = 5; 

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

這個創建圖像5x5px但我はnt圖像例如500x500與領域100x100(1場5x5) – dontHaveName 2012-08-10 15:25:39