使用PHP将单个像素添加到图像中



我正在使用Codeigniter 2.1.3,并希望为图像添加一个像素-我知道GD或ImageMagick应该能够做到这一点,但我发现它们的库非常"臃肿"。有人知道Codeigniter的相对简单的方法吗,甚至还有另一个易于集成的PHP OOP库吗?

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

最新更新