Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/12/2009, 20:40
Avatar de TxT
TxT
 
Fecha de Ingreso: junio-2008
Ubicación: Canada
Mensajes: 272
Antigüedad: 16 años, 9 meses
Puntos: 2
Respuesta: Grave Problema

Código PHP:
<?php

if(isset($_GET['source'])) {
    
highlight_file(__FILE__);
    exit;
}

/**
 * PHPImagen - Manejo de imagenes BETA Release Candidate 3
 * @author Myokram
 * 11/01/08
 */

/**
 * Para usar esta clase:
 * Visita http://php.myokram.info/phpimagen
 *      
 */

class Imagen {
    
    public 
$source null;
    private 
$url "/";
    private 
$ext "jpg";
    private 
$w;
    private 
$h;
    private 
$mh;
    private 
$mw;
    private 
$rh;
    private 
$rw;
    private 
$cut 0;
    private 
$info = array();
    private 
$f1 "imagecreatefromjpeg";
    private 
$f2 "imageJpeg";
    private 
$type "jpeg";
    private 
$error false;
    
    public function 
__construct($url=null) {
        
$url trim($url);
        if(empty(
$url)) {
            
$this->info['basename'] = "rd_".substr(md5(rand()),0,8).".jpg";
            
$this->error("No se especifico la imagen");
            return;
        }
        
$this->url $url;
        if(
$resources $this->getResources($this->url)) {
            
$this->f1 $resources[0];
            
$this->f2 $resources[1];
            
$this->type $resources[2];
            
$this->info $resources[3];
        } else return 
false;
        
$f1 $this->f1;
        
$this->source = @$f1($this->url);
        if (!
$this->source) {
            
$this->error("No se pudo abrir la imagen");
            return 
false;
        }
        
$this->imagesx($this->source);
        
$this->imagesy($this->source);
        
$this->rh $this->h;
        
$this->rw $this->w;
        return 
true;
    }
    
    public function 
resize($maxancho=null,$maxalto=null,$cut=false) {
        if(
$this->stop()) 
            return;
        if(
$cut != false$this->cut true;
        
$this->mw = (!is_numeric($maxancho) or $maxancho 1) ? $this->intval($maxancho);
        
$this->mh = (!is_numeric($maxalto) or $maxalto 1) ? $this->intval($maxalto);
        
$diff_w $this->w/$this->mw;
        
$diff_h $this->h/$this->mh;
        if(
$this->cut == true) {
            
$this->rh $this->mh;
            
$this->rw $this->mw;
            if(
$diff_w $diff_h) {
                
$prop $this->mh/$this->h;
                
$this->mw round($this->w*$prop);
                
$dist_x = ($this->rw-$this->mw)/2;
            } else {
                
$prop $this->mw/$this->w;
                
$this->mh round($this->h*$prop);
                
$dist_y = ($this->rh-$this->mh)/2;
            }
        } else {
            if(
$diff_w $diff_h) {
                
$prop $this->mw/$this->w;
                
$this->mh round($this->h*$prop);
            } else {
                
$prop $this->mh/$this->h;
                
$this->mw round($this->w*$prop);
            }
            
$this->rw $this->mw;
            
$this->rh $this->mh;
        }
        
$output imagecreatetruecolor($this->rw$this->rh);
        if(
$this->type == "gif" or $this->type == "png") {
            
$trn_i imagecolortransparent($this->source);
            if (
$trn_i >= 0) {
                
$trn_c imagecolorsforindex($this->source$trn_i);
                
$trn_i imagecolorallocate($output$trn_c['red'], $trn_c['green'], $trn_c['blue']);
                
imagefill($output00$trn_i);
                
imagecolortransparent($output$trn_i);
            } elseif(
$this->type == "png") {
                
imagealphablending($outputfalse);
                
$color imagecolorallocatealpha($output000127);
                
imagefill($output00$color);
                
imagesavealpha($outputtrue);
            } 
        }
        
$r imagecopyresampled($output$this->source$dist_x$dist_y00$this->mw$this->mh$this->w$this->h);
        
$this->source $output;
        return 
$r;
    }
    
    private function 
getResources($file) {
        
$info pathinfo($file);
        
$info['extension'] = strtolower($info['extension']);
        
$r = array();
        switch(
$info['extension']) {
            case 
'jpg'$r[0] = "imagecreatefromjpeg"$r[1] = "imageJpeg"$r[2] = "jpeg"; break;
            case 
'gif'$r[0] = "imagecreatefromgif"$r[1] = "imageGif"$r[2] = "gif"; break;
            case 
'png'$r[0] = "imagecreatefrompng"$r[1] = "imagePng"$r[2] = "png"; break;
            default: 
$this->info['basename'] = $this->info['basename'].".jpg"$this->error("El tipo de archivo definido no es válido"); return false; break;
        }
        
$r[3] = $info
        return 
$r;
    }
    
    private function 
rgbhex2rgb($c) {
        if(
$this->stop()) 
            return;
        if(!
$c) return false;
        
$c trim($c);
        
$out = array();
        if(
eregi("^[0-9ABCDEFabcdef\#]+$"$c)){
            
$c str_replace('#',''$c);
            
$l strlen($c);
            if(
$l != and $l != 6) return false;
            
$out[0] = $out['r'] = $out['red'] = ($l == 3) ? hexdec(substr($c,0,1).substr($c,0,1)) : hexdec(substr($c,0,2));
            
$out[1] = $out['g'] = $out['green'] = ($l == 3) ? hexdec(substr($c,1,1).substr($c,1,1)) : hexdec(substr($c,2,2));
            
$out[2] = $out['b'] = $out['blue'] = ($l == 3) ? hexdec(substr($c,2,1).substr($c,2,1)) : hexdec(substr($c,4,2));
        } elseif (
eregi("^[0-9]+(,| |.)+[0-9]+(,| |.)+[0-9]+$"$c)){
            if(
eregi(","$c)) $e explode(",",$c);
            elseif(
eregi(" "$c)) $e explode(" ",$c);
            elseif(
eregi("."$c)) $e explode(".",$c);
            else return 
false;
            if(
count($e) != 3) return false;
            if(
is_numeric($e[0]) and $e[0] >= and $e[0] <= 255)
                
$out[0] = $out['r'] = $out['red'] = intval($e[0]);
            if(
is_numeric($e[1]) and $e[1] >= and $e[1] <= 255)
                
$out[1] = $out['g'] = $out['green'] = intval($e[1]);
            if(
is_numeric($e[2]) and $e[2] >= and $e[2] <= 255)
                
$out[2] = $out['b'] = $out['blue'] = intval($e[2]);
        } 
        return (
count($out) != 9) ? false $out;
    }
    
    private function 
error($msg) {
        
$width strlen($msg)*8;
        
$width = ($width 370) ? 370 $width;
        
$url = (strlen($this->url) > 45) ? substr($this->url,0,33)."...".substr($this->url,-10) : $this->url;
        
$this->rw $width;
        
$this->rh 145;
        
$this->source = @imagecreate ($this->rw$this->rh);
        
$background_color imagecolorallocate ($this->source230230230);
        
$text_color_red imagecolorallocate ($this->source255,0,0);
        
$text_color_black imagecolorallocate ($this->source505050);
        
$text_color_green imagecolorallocate ($this->source01500);
        
$text_color_blue imagecolorallocate ($this->source00150);
        
imagestring ($this->source51920"ERROR: LA IMAGEN NO PUDO SER CARGADA"$text_color_red);
        
imagestring ($this->source31650"Hubo un error procesando la imagen:"$text_color_black); 
        
imagestring ($this->source31665$url$text_color_green); 
        
imagestring ($this->source31695$msg$text_color_blue);
        
imagestring ($this->source210125sprintf(base64_decode("UEhQSW1hZ2VuIChjKSVzIC0gQnkgTXlPa3JhbQ=="),date('Y')),$text_color_black);
        
$this->error true;
        return 
true;
    }
    
    private function 
stop() {
        return (
$this->error !== false);
    }
    
    public function 
doPrint($quality=null) {
        
$quality = (is_numeric($quality) and $quality <= 100 and $quality >= 1) ? intval($quality) : 75;
        
Header("Content-type: image/".$this->type);
        
$f2 $this->f2;
        switch(
$this->type) {
            case 
"gif":
                
imagegif($this->source);
                break;
            case 
"jpeg":
                
imagejpeg($this->source,null,$quality);
                break;
            case 
"png":
                
$quality 10 - (round($quality 10));
                
imagepng($this->source,null,$quality,PNG_ALL_FILTERS);
                break;
        } 
        exit;
    }
__________________
<?PHP if( nuevo() ) {
echo 'Bienvenid@ a ForosDelWeb, seguro que tus dudas seran bien respondidas y que tu ayuda sera bien agradecida.';
} ?>