将多个十六进制颜色转换为图像
问题描述:
是否有将函数将十六进制颜色转换为图像并将其保存为png? 例如:将多个十六进制颜色转换为图像
$pixelrow1 ["000000","000000","000000"];
$pixelrow2 ["000000","FFFFFF","000000"];
$pixelrow3 ["FF0000","00FF00","0000FF"];
function convert_to_image($row1,$row2,$row3,$path_to_save) {
// Some function
}
convert_to_image($pixelrow1,$pixelrow2,$pixelrow3,"c:/image.png");
我真的不知道,如果是有可能或没有,但我敢肯定它的可能的,因为你可以使用PHP
答
你能做到这样,但希望您的变量有更明智的名称,你可以使用一个循环:
<?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");
?>
+0
感谢您的回答! –
答
真正的问题是没有将数据保存到所需的文件中。
真正的问题是将数据保存为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);
?>
如果你想看看所有的函数图像:
+0
感谢您的回答 –
你想要什么转换图像多数民众赞成在罚款,但$ row1,$ row2,$ row3有3种颜色,以及它如何在图像中使用? – RJParikh
我编辑了问题主体,你能重新检查一下吗? –
请告诉我你的数据是在一个数组中 - 而不是像'$ pixelrow1'这样的东西。 –