将多个十六进制颜色转换为图像

时间:2016-05-23 13:29:19

标签: php image converter pixels

是否有一个将十六进制颜色转换为图像并将其保存为png的函数? 例如:

sum(list)/len(list)

我真的不知道是否可能,但我很确定它可能因为你可以使用php制作图像

输出应该像这样返回: enter image description here

2 个答案:

答案 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);
?>

如果你想看一下图像的所有功能:

http://php.net/manual/en/ref.image.php

答案 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");
?>

enter image description here