Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/08/2010, 07:59
guichitos
 
Fecha de Ingreso: agosto-2008
Mensajes: 12
Antigüedad: 15 años, 8 meses
Puntos: 0
Header no redireccionar al llamar a clase

Muy buenas al foro. mi problema es el siguiente:

Dentro mi web tengo un formulario que le permite al usuario cargar una fotografia. en mi pagina php que procesa toda esta informacion + la foto, proceso la imagen mediante el script de Zubrag de manera de obtener thumps que usare luego. El problema es que en cuanto el código de este script llama a la clase Zubrag_image ya no puedo imprimir en pantalla nada ni utilizar el header para redireccionar la pagina (obviamente no intento hacer ambas cosas al mismo tiempo :) ). si no incluyo esta linea realiza el redireccionado perfectamente.

El script es el siguiente:

Código PHP:
$save_to_file true;
    
$image_quality 100;
    
$image_type = -1;
    
$max_x 100;
    
$max_y 100;
    
$cut_x 0;
    
$cut_y 0;
    
$images_folder '../images/';
    
$thumbs_folder '../Centros/1/';
    
$thumbs1_folder '../Centros/2/';
    
$to_name '';
    
$save_to_file == 1;
    
$n_arch_alm=$numusuario.".".$extension;
    
$from_name urldecode($n_arch_alm);
    
$to_name urldecode($n_arch_alm);
    if (!
file_exists($images_folder)) die('Images folder does not exist (update $images_folder in the script)');
    if (
$save_to_file && !file_exists($thumbs_folder)) die('Thumbnails folder does not exist (update $thumbs_folder in the script)');
    
ini_set('memory_limit''-1');
    include(
'../image.class.php');
    
    
$img = new Zubrag_image//  !!!!! linea problematica si incluyo esta no redirecciona!!!!
    //generar la primera copia
    
$img->max_x        $max_x;
    
$img->max_y        $max_y;
    
$img->cut_x        $cut_x;
    
$img->cut_y        $cut_y;
    
$img->quality      $image_quality;
    
$img->save_to_file $save_to_file;
    
$img->image_type   $image_type;
    
$img->GenerateThumbFile($images_folder $from_name$thumbs_folder $to_name);
    
//generar la segunda copia
    
$img->max_x        200;
    
$img->max_y        200;
    
$img->cut_x        $cut_x;
    
$img->cut_y        $cut_y;
    
$img->quality      $image_quality;
    
$img->save_to_file $save_to_file;
    
$img->image_type   $image_type;
    
$img->GenerateThumbFile($images_folder $from_name$thumbs1_folder $to_name);
    
    
header("location:../centro_inscrito_ok.php?num=$numusuario&dataimg=$img"); // !!! esta es la linea que no me corre !!! 

y la clase del archivo image.class.ph es la siguiente

Código PHP:
<?php
class Zubrag_image {
  var 
$save_to_file true;
  var 
$image_type = -1;
  var 
$quality 100;
  var 
$max_x 100;
  var 
$max_y 100;
  var 
$cut_x 0;
  var 
$cut_y 0;
  function 
SaveImage($im$filename) {
     
$res null;
     
// ImageGIF is not included into some GD2 releases, so it might not work
    // output png if gifs are not supported
    
if(($this->image_type == 1)  && !function_exists('imagegif')) $this->image_type 3;
    switch (
$this->image_type) {
      case 
1:
        if (
$this->save_to_file) {
          
$res ImageGIF($im,$filename);
        }
        else {
          
header("Content-type: image/gif");
          
$res ImageGIF($im);
        }
        break;
      case 
2:
        if (
$this->save_to_file) {
          
$res ImageJPEG($im,$filename,$this->quality);
        }
        else {
          
header("Content-type: image/jpeg");
          
$res ImageJPEG($imNULL$this->quality);
        }
        break;
      case 
3:
        if (
PHP_VERSION >= '5.1.2') {
          
// Convert to PNG quality.
          // PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
          
$quality minround($this->quality 10), );
          if (
$this->save_to_file) {
            
$res ImagePNG($im$filename$quality);
          }
          else {
            
header("Content-type: image/png");
            
$res ImagePNG($imNULL$quality);
          }
        }
        else {
          if (
$this->save_to_file) {
            
$res ImagePNG($im$filename);
          }
          else {
            
header("Content-type: image/png");
            
$res ImagePNG($im);
          }
        }
        break;
    }
 
    return 
$res;
 
  }
 
  function 
ImageCreateFromType($type,$filename) {
   
$im null;
   switch (
$type) {
     case 
1:
       
$im ImageCreateFromGif($filename);
       break;
     case 
2:
       
$im ImageCreateFromJpeg($filename);
       break;
     case 
3:
       
$im ImageCreateFromPNG($filename);
       break;
    }
    return 
$im;
  }
 
  
// generate thumb from image and save it
  
function GenerateThumbFile($from_name$to_name) {
 
    
// if src is URL then download file first
    
$temp false;
    if (
substr($from_name,0,7) == 'http://') {
      
$tmpfname tempnam("tmp/""TmP-");
      
$temp = @fopen($tmpfname"w");
      if (
$temp) {
        @
fwrite($temp, @file_get_contents($from_name)) or die("Cannot download image");
        @
fclose($temp);
        
$from_name $tmpfname;
      }
      else {
        die(
"Cannot create temp file");
      }
    }

    
// check if file exists
    
if (!file_exists($from_name)) die("Source image does not exist!");
    
    
// get source image size (width/height/type)
    // orig_img_type 1 = GIF, 2 = JPG, 3 = PNG
    
list($orig_x$orig_y$orig_img_type$img_sizes) = @GetImageSize($from_name);

    
// cut image if specified by user
    
if ($this->cut_x 0$orig_x min($this->cut_x$orig_x);
    if (
$this->cut_y 0$orig_y min($this->cut_y$orig_y);
 
    
// should we override thumb image type?
    
$this->image_type = ($this->image_type != -$this->image_type $orig_img_type);
 
    
// check for allowed image types
    
if ($orig_img_type or $orig_img_type 3) die("Image type not supported");
 
    if (
$orig_x $this->max_x or $orig_y $this->max_y) {
 
      
// resize
      
$per_x $orig_x $this->max_x;
      
$per_y $orig_y $this->max_y;
      if (
$per_y $per_x) {
        
$this->max_x $orig_x $per_y;
      }
      else {
        
$this->max_y $orig_y $per_x;
      }
 
    }
    else {
      
// keep original sizes, i.e. just copy
      
if ($this->save_to_file) {
        @
copy($from_name$to_name);
      }
      else {
        switch (
$this->image_type) {
          case 
1:
           
//   header("Content-type: image/gif");
              
readfile($from_name);
            break;
          case 
2:
             
// header("Content-type: image/jpeg");
              
readfile($from_name);
            break;
          case 
3:
            
//  header("Content-type: image/png");
              
readfile($from_name);
            break;
        }
      }
      return;
    }
 
    if (
$this->image_type == 1) {
      
// should use this function for gifs (gifs are palette images)
      
$ni imagecreate($this->max_x$this->max_y);
    }
    else {
      
// Create a new true color image
      
$ni ImageCreateTrueColor($this->max_x,$this->max_y);
    }
 
    
// Fill image with white background (255,255,255)
    
$white imagecolorallocate($ni255255255);
    
imagefilledrectangle$ni00$this->max_x$this->max_y$white);
    
// Create a new image from source file
    
$im $this->ImageCreateFromType($orig_img_type,$from_name);
    
// Copy the palette from one image to another
    
imagepalettecopy($ni,$im);
    
// Copy and resize part of an image with resampling
    
imagecopyresampled(
      
$ni$im,             // destination, source
      
0000,           // dstX, dstY, srcX, srcY
      
$this->max_x$this->max_y,       // dstW, dstH
      
$orig_x$orig_y);    // srcW, srcH
 
    // save thumb file
    
$this->SaveImage($ni$to_name);

    if(
$temp) {
      
unlink($tmpfname); // this removes the file
    
}

  }

}

?>
El problema como les dije qe suq eno me redirecciona y solo me aprece la pagina en blanco sin ningun mensaje de error