imagecolorallocate accuracy problem
Posted: Mon Apr 12, 2010 12:33 am
I've been experimenting with different methods of storing photo data in MySQL. So, not the location to a photo, but the actual data. I have one script that takes in a photo and puts the data in the database by looping through each pixel and using imagecolorat and converting the rgb to html, and another script that can read the stored data and create an image by converting the html back to rgb and using imagecolorallocate and imagesetpixel. The data stored in the database looks like this:
(condensed)
0=263435&1=1c2524&2=141613&3=e0f09&4=171a13&5=282d27&6=36413b&7=3a4b45&8=32424f&9=253a3f ...
(exploded)
0=263435
1=1c2524
2=141613
3=e0f09
4=171a13
5=282d27
6=36413b
7=3a4b45
8=32424f
9=253a3f
...
where the first number is an index in the image, starting at the top left corner and going down. So, if the image has a height of 137 pixels then an index value of 159 would correspond to (x, y) = (1, 22) by these equations $x = floor($index/$height); $y = $index - ($x*$height); (first row and column are zero, so its actually the 23rd row and 2nd column).
Anyways, it sort of works, but I can't figure out why the image I piece back together has artifacts.
Here is the original image:

Here is the generated image:

I've already checked the database values for some of the funky pixels and the right value was stored, but it doesn't set the right color to the image. Also, it doesn't matter how many times I run the scripts, the artifacts end up in the same spots every time. Would this be a memory problem?
Any help would be appreciated. Thanks.
(condensed)
0=263435&1=1c2524&2=141613&3=e0f09&4=171a13&5=282d27&6=36413b&7=3a4b45&8=32424f&9=253a3f ...
(exploded)
0=263435
1=1c2524
2=141613
3=e0f09
4=171a13
5=282d27
6=36413b
7=3a4b45
8=32424f
9=253a3f
...
where the first number is an index in the image, starting at the top left corner and going down. So, if the image has a height of 137 pixels then an index value of 159 would correspond to (x, y) = (1, 22) by these equations $x = floor($index/$height); $y = $index - ($x*$height); (first row and column are zero, so its actually the 23rd row and 2nd column).
Anyways, it sort of works, but I can't figure out why the image I piece back together has artifacts.
Here is the original image:

Here is the generated image:

I've already checked the database values for some of the funky pixels and the right value was stored, but it doesn't set the right color to the image. Also, it doesn't matter how many times I run the scripts, the artifacts end up in the same spots every time. Would this be a memory problem?
Any help would be appreciated. Thanks.
