Ver Mensaje Individual
  #6 (permalink)  
Antiguo 25/05/2009, 05:04
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Reescalar imagen - Guardarla luego

continuar

Código PHP:

    
/**
     *  Creates a target image identifier
     *
     *  @access private
     */
    
function create_target_image_identifier($width$height)
    {
    
        
// creates a blank image
        
$targetImageIdentifier imagecreatetruecolor((int)$width <= : (int)$width, (int)$height <= : (int)$height);
        
        
// if we have transparency in the image
        
if (isset($this->transparentColorRed) && isset($this->transparentColorGreen) && isset($this->transparentColorBlue)) {
        
            
$transparent imagecolorallocate($targetImageIdentifier$this->transparentColorRed$this->transparentColorGreen$this->transparentColorBlue);

            
imagefilledrectangle($targetImageIdentifier00$width$height$transparent);

            
imagecolortransparent($targetImageIdentifier$transparent);
            
        }
        
        
// return target image identifier
        
return $targetImageIdentifier;
        
    }

    
/**
     *  creates a new image from a given image identifier
     *
     *  @access private
     */
    
function output_target_image($targetImageIdentifier)
    {
    
        
// get target file extension
        
$targetFileExtension strtolower(substr($this->targetFilestrrpos($this->targetFile".") + 1));
        
        
// image saving process goes according to required extension
        
switch ($targetFileExtension) {
        
            
// if gif
            
case "gif":
            
                
// if gd support for this file type is not available
                
if (!function_exists("imagegif")) {
                
                    
// save the error level and stop the execution of the script
                    
$this->error 6;

                    return 
false;
                    
                
// if, for some reason, file could not be created
                
} elseif (@!imagegif($targetImageIdentifier$this->targetFile)) {
                
                    
// save the error level and stop the execution of the script
                    
$this->error 3;

                    return 
false;
                    
                }
                
                break;
                
            
// if jpg
            
case "jpg":
            case 
"jpeg":
            
                
// if gd support for this file type is not available
                
if (!function_exists("imagejpeg")) {
                
                    
// save the error level and stop the execution of the script
                    
$this->error 6;

                    return 
false;
                    
                
// if, for some reason, file could not be created
                
} elseif (@!imagejpeg($targetImageIdentifier$this->targetFile$this->jpegOutputQuality)) {
                
                    
// save the error level and stop the execution of the script
                    
$this->error 3;

                    return 
false;
                    
                }
                
                break;
                
            case 
"png":
            
                
// if gd support for this file type is not available
                
if (!function_exists("imagepng")) {
                
                    
// save the error level and stop the execution of the script
                    
$this->error 6;

                    return 
false;
                    
                
// if, for some reason, file could not be created
                
} elseif (@!imagepng($targetImageIdentifier$this->targetFile)) {
                
                    
// save the error level and stop the execution of the script
                    
$this->error 3;

                    return 
false;
                    
                }
                
                break;
                
            
// if not a supported file extension
            
default:
            
                
// save the error level and stop the execution of the script
                
$this->error 5;

                return 
false;
                
        }
        
        
// if file was created successfully
        // chmod the file
        
chmod($this->targetFileintval($this->chmodValue8));
        
        
// if the date/time of the target file should be the same as the source file's
        
if ($this->preserveSourceFileTime) {
        
            
// touch the newly created file
            
@touch($this->targetFile$this->sourceFileTime);
            
        }
        
        
// and return true
        
return true;
        
    }