PHP image creation from hex values in database

拟墨画扇 提交于 2019-12-02 12:38:46

$x = 0; is executed in each iteration of the while loop. You need to move the initialization in front the loop.

You just need to move $x = 0; to before the start of the loop.

There seem to be a few other things wrong, too

$x = 0;

while($colors = mysql_fetch_array( $sql ))
{
    $imgname = $x.".jpg";

    $color = $colors['value'];

    // Skip the whole lot if the colour is invalid
    if (strlen($color) != 6)
        continue;

    // No need to create an array just to call list()
    $r = hexdec($color[0].$color[1]);
    $g = hexdec($color[2].$color[3]);
    $b = hexdec($color[4].$color[5]);

    // There's no need to header() if you're writing to a file
    //header("Content-type: image/jpeg");
    $image = imagecreate( 720, 576 );
    $colour = imagecolorallocate($image, $r, $g, $b);

    // You don't actually fill the image with the colour
    imagefilledrectangle($image, 0, 0, 719, 575, $colour);

    imagejpeg($image, $imgname);
    imagedestroy($image);

    $x++;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!