single pixel manipulation with php GD

前端 未结 3 487
南笙
南笙 2021-01-23 18:26

First I\'m referring to a previous question Change image per pixel and save to db

I found that the html5 canvas isn\'t suitable because it\'s hard to keep the source-ima

3条回答
  •  耶瑟儿~
    2021-01-23 18:52

    replace RANDOM_COLOR with your random color value

    this will replace all the pixels ,

    for($i=0;$i < $x;$i++) {
        for($e = 0;$e < $y;$e++) {
            imagesetpixel($gd, $i,$e, $RANDOM_COLOR);
        }
    }
    

    if you want to set only a few random pixels , make sure you set them in a 0 and width -1, 0 and height -1 range

    for example

    $i = rand(0,$width-1);
    $e = rand(0,$height - 1);
    imagesetpixel($gd, $i,$e, $RANDOM_COLOR);
    

    you could use it in a loop

提交回复
热议问题