1
<?php

    $src    = 'white.jpg';
    $im     = imagecreatefromjpeg($src);
    $size   = getimagesize($src);
    $width  = $size[0];
    $height = $size[1];
    $count = 1;
    $f_string = "";
    $f_string2 = "";
    for($x=0;$x<$width;$x++)
    {
        for($y=0;$y<$height;$y++)
        {
            $acepted = 0;
            $rgb1 = imagecolorat($im, $x, $y);
            $rgb2 = imagecolorat($im, $x+1, $y);
            $rgb3 = imagecolorat($im, $x+2, $y);
            $rgb4 = imagecolorat($im, $x, $y+1);
            $rgb5 = imagecolorat($im, $x+1, $y+1);
            $rgb6 = imagecolorat($im, $x+2, $y+1);
            $rgb7 = imagecolorat($im, $x, $y+3);
            $rgb8 = imagecolorat($im, $x+1, $y+3);
            $rgb9 = imagecolorat($im, $x+2, $y+3);
            $rgb10 = imagecolorat($im, $x+3, $y);
            $rgb11 = imagecolorat($im, $x+3, $y+1);
            $rgb12 = imagecolorat($im, $x+3, $y+2);
            $rgb13 = imagecolorat($im, $x+3, $y+3);
            $rgb14 = imagecolorat($im, $x+1, $y+3);
            $rgb15 = imagecolorat($im, $x+2, $y+3);
            $rgb16 = imagecolorat($im, $x+3, $y+3);

            $colors1 = imagecolorsforindex($im, $rgb1);
            $colors2 = imagecolorsforindex($im, $rgb2);
            $colors3 = imagecolorsforindex($im, $rgb3);
            $colors4 = imagecolorsforindex($im, $rgb4);
            $colors5 = imagecolorsforindex($im, $rgb5);
            $colors6 = imagecolorsforindex($im, $rgb6);
            $colors7 = imagecolorsforindex($im, $rgb7);
            $colors8 = imagecolorsforindex($im, $rgb8);
            $colors9 = imagecolorsforindex($im, $rgb9);
            $colors10 = imagecolorsforindex($im, $rgb10);
            $colors11 = imagecolorsforindex($im, $rgb11);
            $colors12 = imagecolorsforindex($im, $rgb12);
            $colors13 = imagecolorsforindex($im, $rgb13);
            $colors14 = imagecolorsforindex($im, $rgb14);
            $colors15 = imagecolorsforindex($im, $rgb15);
            $colors16 = imagecolorsforindex($im, $rgb16);


            if($colors1["red"] < 60 && $colors1["green"] < 60 && $colors1["blue"] < 60 && $colors1["alpha"] < 50) { $acepted++; }
            if($colors2["red"] < 60 && $colors2["green"] < 60 && $colors2["blue"] < 60 && $colors2["alpha"] < 50) { $acepted++; }
            if($colors3["red"] < 60 && $colors3["green"] < 60 && $colors3["blue"] < 60 && $colors3["alpha"] < 50) { $acepted++; }
            if($colors4["red"] < 60 && $colors4["green"] < 60 && $colors4["blue"] < 60 && $colors4["alpha"] < 50) { $acepted++; }
            if($colors5["red"] < 60 && $colors5["green"] < 60 && $colors5["blue"] < 60 && $colors5["alpha"] < 50) { $acepted++; }
            if($colors6["red"] < 60 && $colors6["green"] < 60 && $colors6["blue"] < 60 && $colors6["alpha"] < 50) { $acepted++; }
            if($colors7["red"] < 60 && $colors7["green"] < 60 && $colors7["blue"] < 60 && $colors7["alpha"] < 50) { $acepted++; }
            if($colors8["red"] < 60 && $colors8["green"] < 60 && $colors8["blue"] < 60 && $colors8["alpha"] < 50) { $acepted++; }
            if($colors9["red"] < 60 && $colors9["green"] < 60 && $colors9["blue"] < 60 && $colors9["alpha"] < 50) { $acepted++; }
            if($colors10["red"] < 60 && $colors10["green"] < 60 && $colors10["blue"] < 60 && $colors10["alpha"] < 50) { $acepted++; }
            if($colors11["red"] < 60 && $colors11["green"] < 60 && $colors11["blue"] < 60 && $colors11["alpha"] < 50) { $acepted++; }
            if($colors12["red"] < 60 && $colors12["green"] < 60 && $colors12["blue"] < 60 && $colors12["alpha"] < 50) { $acepted++; }
            if($colors13["red"] < 60 && $colors13["green"] < 60 && $colors13["blue"] < 60 && $colors13["alpha"] < 50) { $acepted++; }
            if($colors14["red"] < 60 && $colors14["green"] < 60 && $colors14["blue"] < 60 && $colors14["alpha"] < 50) { $acepted++; }
            if($colors15["red"] < 60 && $colors15["green"] < 60 && $colors15["blue"] < 60 && $colors15["alpha"] < 50) { $acepted++; }
            if($colors16["red"] < 60 && $colors16["green"] < 60 && $colors16["blue"] < 60 && $colors16["alpha"] < 50) { $acepted++; }



        if($acepted > 6) {
$stringx = $y;
$stringy = $x;
$string2 = $stringx+1;
$string3 = $stringy+1;
$f_string .= "
v $stringx $stringy 0
v $string2 $stringy 0
v $string2 $string3 0
v $stringx $string3 0";


            $count2 = $count+1;
            $count3 = $count2+1;
            $count4 = $count3+1;


            $f_string2 .= "
f  $count//$count2  $count2//$count3  $count3//$count4";


$count++;

            }       


            ///echo"$r $g $b <br> ";    

            /*if($r != 0 || $g != 0 || $b != 0) {
            echo"$r $g $b <br> ";   
            }*/

            /*if($colors["red"] < 60 && $colors["green"] < 60 && $colors["blue"] < 60 && $colors["alpha"] < 50) {
            $count++;   
            }*/

            //var_dump($r, $g, $b);
        }
    }
//echo $count;
//echo "<br>";

$myfile = fopen("model_gen2.obj", "w") or die("Unable to open file!");
$f_final3 = "
# cube.obj
#

g cube

$f_string

$f_string2";
fwrite($myfile, $f_final3);
fclose($myfile);
echo"Done! ($count)";
//print($f_string);
?>

In short, here's what happens:

  1. PHP goes threw every pixel on the image
  2. If pixel is black, it adds it's coordinated to obj file
  3. It exports the file to a .obj file

If anyone has some spare time, could you help me out

  1. Could anyone tell me how should I format my .obj string to start extruding, like giving a default value of 1 or two in the z-axis?
  2. Could anyone tell me why only a third of the image gets converted? (I attached my image and result)

Here is my image:
My image

Here is the result:
Result

gre_gor
  • 6,669
  • 9
  • 47
  • 52

0 Answers0