1

Can someone help me to draw single pixel using php GD library? I have such code:

$img    = imagecreatetruecolor(100, 100);
$c      = imagecolorallocate($img, 255, 0, 0);
$white  = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $white);
imagesetpixel($img, 0, 0, $c);
imagejpeg($img, 'created.jpg');die();

But the output is really weird (it is approximate image in top-left corner):

enter image description here

Is it possible to draw just one red pixel at x-0 y-0 position?

J Price
  • 56
  • 6
  • 3
    Use png instead of jpg, jpg uses lossy encoding, losing information in the progress – Ferrybig Feb 01 '17 at 12:20
  • Thanks mate. It seems like it is impossible to make something with jpeg :( – J Price Feb 01 '17 at 12:31
  • 2
    You may want to read about the different image file types, and in what situations they are useful: [PNG vs. GIF vs. JPEG vs. SVG - When best to use?](http://stackoverflow.com/a/7752936/1542723) – Ferrybig Feb 01 '17 at 12:35

0 Answers0