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

Continuación:
Código PHP:
    public function doSave($destination,$quality=null) {
        
$quality = (is_numeric($quality) and $quality <= 100 and $quality >= 1) ? intval($quality) : 75;
        
Header("Content-type: image/".$this->type);
        
$f2 = $this->f2;
        
$info = pathinfo($destination);
        if(empty(
$info['filename']))
            
$this->error("Para guardar se debe especificar un nombre de archivo válido");
        if(
$info['extension'] !== $this->info['extension'])
            
$destination .= ".".$this->info['extension'];
        switch(
$this->type) {
            case 
"gif":
                return 
imagegif($this->source,$destination);
                break;
            case 
"jpeg":
                return 
imagejpeg($this->source,$destination,$quality);
                break;
            case 
"png":
                
$quality = 10 - (round($quality / 10));
                return 
imagepng($this->source,$destination,$quality,PNG_ALL_FILTERS);
                break;
        } 
        return 
false;
    }
    
    public function 
doDownload($quality=null) {
        
$quality = (is_numeric($quality) and $quality <= 100 and $quality >= 1) ? intval($quality) : 75; 
        
header("Content-type: application/octet-stream");
        
header("Content-Disposition: attachment; filename=\"".$this->info['basename']."\"\n");
        
$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;
    }
    
    public function 
watermark($file,$posx = 0,$posy = 0,$loop=false,$rotation = 0) {
        if(
$this->stop()) 
            return;
        if(
false == ($resources = $this->getResources($file)))
            return;
        
$f1 = $resources[0];
        if(
false == ($wm = @$f1($file)))
            return 
$this->error("La marca de agua \"$file\"no pudo ser cargada");
            
        if(
$resources[3]['extension'] == "gif") {
            
$newwm = md5($file.rand()).".png";
            
imagepng($wm,$newwm);
            if(
file_exists($newwm)) { 
                
$wm = imagecreatefrompng($newwm);
                @
unlink($newwm);
            }
        }
        
        if(
$rotation <> 0 and is_numeric($rotation)) 
            
$wm = imagerotate($wm, $rotation, -1);
            
        
$wm_w = @imagesx($wm);
        
$wm_h = @imagesy($wm);
        
        if(
$this->type == "gif") {
            
$matte = imagecreatetruecolor($wm_w,$wm_h);
            
$trans_color = imagecolorallocatealpha($matte,254,254,254,0);
            
imagefill($matte, 0,0,$trans_color);
            
imagecopy($matte,$wm,0,0,0,0,$wm_w,$wm_h);
            
imagecolortransparent($matte,$trans_color);
            
$wm = $matte;
        }
        
        
imagealphablending($this->source, true);  
        
imagesavealpha($this->source, true); 
        
imagealphablending($wm, false);  
        
        
$posx = ($posx === false) ? ($this->rw - $wm_w) / 2 : intval($posx);
        
$posy = ($posy === false) ? ($this->rh - $wm_h) / 2 : intval($posy);
        if(
$posx < 0) $posx = ($this->rw - $wm_w) + $posx;
        if(
$posy < 0) $posy = ($this->rh - $wm_h) + $posy;
        
        
$this->imagecopy2($this->source, $wm, $posx, $posy, 0, 0, $wm_w, $wm_h, 100);
        
        if(
$loop === 1 or $loop === 3) {
            
$rest = ceil($posx/$wm_w);
            
$n = 1;
            while(
$n <= $rest) {
                
$this->imagecopy2($this->source, $wm, $posx-($wm_w*$n), $posy, 0, 0, $wm_w, $wm_h, 100);
                
$n++;
            }
            
$rest = ceil(($this->rw - $posx)/$wm_w);
            
$n = 1;
            while(
$n <= $rest) {
                
$this->imagecopy2($this->source, $wm, $posx+($wm_w*$n), $posy, 0, 0, $wm_w, $wm_h, 100);
                
$n++;
            }
        } 
        if(
$loop === 2 or $loop === 3) {
            
$rest = ceil($posy/$wm_h);
            
$n = 1;
            while(
$n <= $rest) {
                
$this->imagecopy2($this->source, $wm, $posx, $posy-($wm_h*$n), 0, 0, $wm_w, $wm_h, 100);
                
$n++;
            }
            
$rest = ceil(($this->rh - $posy)/$wm_h);
            
$n = 1;
            while(
$n <= $rest) {
                
$this->imagecopy2($this->source, $wm, $posx, $posy+($wm_h*$n), 0, 0, $wm_w, $wm_h, 100);
                
$n++;
            }
        }
        return 
true;
    }
    
    private function 
imagecopy2(&$s, $wm, $posx, $posy, $srcx, $srcy, $wm_w, $wm_h, $pct = null) {
        if(
$this->type == "gif")
             return 
imagecopymerge($s, $wm, $posx, $posy, $srcx, $srcy, $wm_w, $wm_h, $pct);
        else
             return 
imagecopy($s, $wm, $posx, $posy, $srcx, $srcy, $wm_w, $wm_h);
    }
    
    public function 
textmark($text,$color,$size,$font=null,$rot=0,$posx = 0,$posy = 0) {
        if(
$this->stop()) 
            return;
        if(
$color = $this->rgbhex2rgb($color)) {
            
$color = imagecolorallocate ($this->source, intval($color[0]), intval($color[1]), intval($color[2]));
            
$posx = ($posx === false) ? $this->rw / 2 : intval($posx);
            
$posy = ($posy === false) ? $this->rh / 2 : intval($posy);
            if(
$posx < 0) $posx = $this->rw + $posx;
            if(
$posy < 0) $posy = $this->rh + $posy;
            if(
function_exists("imagettftext") and isset($font)) 
                if(@
imagettftext($this->source, $size, intval($rot), $posx, $posy, $color, $font, $text))
                    return 
true;
            
imagestring($this->source, $size, $posx, $posy, $text, $color);
            return 
true;
        }
        
$this->error("El color de texto debe ser indicado en formato RGB o HTML válido");
        return 
false;
    }
    
    public function 
colorize($color,$exact=false) {
        if(
$this->stop()) 
            return;
        if(
$color = $this->rgbhex2rgb($color)) {
            if(
$exact == true)
                
$this->grayscale();    
            if(
function_exists("imagefilter"))
                return 
imagefilter($this->source, IMG_FILTER_COLORIZE, $color[0], $color[1], $color[2]);
            
imagetruecolortopalette($this->source, FALSE, 1024); 
            
$total = imagecolorstotal($this->source);
            for (
$i = 0; $i < $total; $i++){ 
                
$c = imagecolorsforindex($this->source, $i);           
                
imagecolorset($this->source, $i, $color[0]*$c['red']/256, $color[1]*$c['green']/256, $color[2]*$c['blue']/256);
            }
            return 
true;
        }
        
$this->error("El nuevo color de imagen debe ser indicado en formato RGB o HTML válido");
        return 
false;
    } 
    
    public function 
grayscale() {
        if(
$this->stop()) 
            return;
        if(
function_exists("imagefilter"))
            return 
imagefilter($this->source, IMG_FILTER_GRAYSCALE);
        if(
imageistruecolor($this->source))
            
imagetruecolortopalette($this->source, false, 256);
        
$total = imagecolorstotal($this->source);
        for (
$i = 0; $i < $total; $i++) {
            
$col = imagecolorsforindex($this->source, $i);
            
$gray = round(0.299 * $col['red'] + 0.587 * $col['green'] + 0.114 * $col['blue']);
            
imagecolorset($this->source, $i, $gray, $gray, $gray);
        }
        
imagealphablending($this->source,true);
        
imagesavealpha($this->source,true);
    }
    
}

// Release date: 11/01/2008 @ 21:11:23 GMT-5

?> 
__________________
<?PHP if( nuevo() ) {
echo 'Bienvenid@ a ForosDelWeb, seguro que tus dudas seran bien respondidas y que tu ayuda sera bien agradecida.';
} ?>