答案 0 :(得分:0)
真正的问题不是将数据保存到您想要的文件中。
真正的问题是保存数据IN png格式。
您应该阅读png如何保存数据。
或者您可以使用PHP图像资源进行一些操作。 也许这段代码可以给你一些建议:
<?php
header("Content-Type: image/png");
$im = @imagecreate(1, 1);
// Creates a 1x1 image resource
$background_color = imagecolorallocate($im, 0xFF, 0x00, 0x00);
// Adds a red background color to the only pixel in the image.
imagepng($im);
// Sends the image to the browser.
imagedestroy($im);
?>
如果你想看一下图像的所有功能:
答案 1 :(得分:0)
你可以这样做,但希望你的变量有更明智的名字,你可以使用循环:
<?php
$im = imagecreate(3,3);
$black = imagecolorallocate($im,0,0,0);
$white = imagecolorallocate($im,0xff,0xff,0xff);
$red = imagecolorallocate($im,0xff,0,0);
$green = imagecolorallocate($im,0,0xff,0);
$blue = imagecolorallocate($im,0,0,0xff);
# First row
imagesetpixel($im,0,0,$black);
imagesetpixel($im,1,0,$black);
imagesetpixel($im,2,0,$black);
# Second row
imagesetpixel($im,0,0,$black);
imagesetpixel($im,1,1,$white);
imagesetpixel($im,2,1,$black);
# Third row
imagesetpixel($im,0,2,$red);
imagesetpixel($im,1,2,$green);
imagesetpixel($im,2,2,$blue);
imagepng($im,"result.png");
?>