Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/08/2005, 00:02
Shockly
 
Fecha de Ingreso: agosto-2005
Mensajes: 109
Antigüedad: 18 años, 7 meses
Puntos: 0
Curioso problema(?) con GD

Buenas,

Hace poco registré (no para nada, simplemente porque me gustó el nombre) el dominio 625lineas.com ... y por poner algo diferente a una carta de ajuste (no lo necesito para nada), he puesto una simple ventana que dibuja un cuadro con entre 1 y 312 líneas de longitudes e inclinaciones aleatorias. Hasta ahí todo bién... pero resulta que unas veces las dibuja en el color establecido: negro, y otras ... en azul!!!

La librería es GD 2.0.28 y el programa es el que sigue... y no entiendo el porqué de ese curioso efecto. ¿Alguna idea?

La url es http://625lineas.com (se crea un nuevo cuadro aleatorio con cada click en él).

Un saludo.


Código PHP:
<?
//----------------------------------------------------------
    
error_reportingE_ALL ^ (E_NOTICE E_WARNING) );
//----------------------------------------------------------
// main

    
header("Content-type : image/jpeg");

    
$lines        = @$_REQUEST["lineas"];
    
    if( 
$lines == "" )
        
$lines         1;
    
$lines *= 1.0;        
    if( 
$lines )
        
$lines         1;
    if( 
$lines 312 )
        
$lines         312;

    
$image = @ImageCreate(640480)
        or die (
"Cannot Initialize new GD image stream");
    
$background_color ImageColorAllocate($image245245245);

    
$min_x 0;
    
$max_x 639;
    
$min_y 0;
    
$max_y 479;

    
$r 0;
    
$g 0;
    
$b 255;
        
    for( 
$n=0$n<$lines$n++ ) {
        
$x1 rand $min_x$max_x );
        
$y1 rand $min_y$max_y );
        
$x2 rand $min_x$max_x );
        
$y2 rand $min_y$max_y );
        
drawQSLine$image$x1$y1$x2$y2$r$g$b );
    }

    
ImageJpeg($image);
    
imagedestroy($image);

//----------------------------------------------------------
//  funciones

function drawQSLine ($image,$x1,$y1,$x2,$y2,$r,$g,$b) {
$icr=$r;
$icg=$g;
$icb=$b;
 
$dcol ImageColorAllocate ($image,$icr,$icg,$icb);
 if (
$y1 == $y2imageline ($image,$x1,$y1,$x2,$y1,$dcol);
 else if (
$x1 == $x2) { 
   
imageline ($image,$x1,$y1,$x1,$y2,$dcol);
 } else {
 
$m = ($y2 $y1) / ($x2 $x1);
 
$b $y1 $m $x1;

 if (
abs ($m) <2) {

 
$x min ($x1,$x2);
 
$endx max ($x1,$x2)+1;

 while (
$x $endx) {
 
$y=$m $x $b;
 
$y == floor ($y) ? $ya $ya $y floor ($y);
 
$yb ceil ($y) - $y;
 
 
$trgb ImageColorAt($image,$x,floor($y));
 
$tcr = ($trgb >> 16) & 0xFF;
 
$tcg = ($trgb >> 8) & 0xFF;
 
$tcb $trgb 0xFF;
 
imagesetpixel ($image,$x,floor ($y),imagecolorallocate ($image,($tcr $ya $icr $yb),
(
$tcg $ya $icg $yb),
(
$tcb $ya $icb $yb)));

 
$trgb ImageColorAt($image,$x,ceil($y));
 
$tcr = ($trgb >> 16) & 0xFF;
 
$tcg = ($trgb >> 8) & 0xFF;
 
$tcb $trgb 0xFF;
 
imagesetpixel ($image,$x,ceil ($y),imagecolorallocate ($image,($tcr $yb $icr $ya),
(
$tcg $yb $icg $ya),
(
$tcb $yb $icb $ya)));

 
$x ++;
 } 
# while_x_end
 
# if_end
 
else { # else_abs_end

 
$y min ($y1,$y2);
 
$endy max ($y1,$y2)+1;

 while (
$y $endy) {
 
$x=($y $b) / $m;
 
$x == floor ($x) ? $xa $xa $x floor ($x);
 
$xb ceil ($x) - $x;

 
$trgb ImageColorAt($image,floor($x),$y);
 
$tcr = ($trgb >> 16) & 0xFF;
 
$tcg = ($trgb >> 8) & 0xFF;
 
$tcb $trgb 0xFF;
 
imagesetpixel ($image,floor ($x),$y,imagecolorallocate ($image,($tcr $xa $icr $xb),
(
$tcg $xa $icg $xb),
(
$tcb $xa $icb $xb)));

 
$trgb ImageColorAt($image,ceil($x),$y);
 
$tcr = ($trgb >> 16) & 0xFF;
 
$tcg = ($trgb >> 8) & 0xFF;
 
$tcb $trgb 0xFF;
 
imagesetpixel ($image,ceil ($x),$y,imagecolorallocate ($image, ($tcr $xb $icr $xa),
(
$tcg $xb $icg $xa),
(
$tcb $xb $icb $xa)));

 
$y ++;
 }
# while_y_end
 
}# else_abs_end
 
}# else_y=y_x=x_end
}# drawOSLine_end

//----------------------------------------------------------
//  END
?>