Visualizzazione dei risultati da 1 a 4 su 4

Discussione: problema upload png

  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    problema upload png

    ciao, quando vado a caricare una png mi da pagina bianca, come mai? cosa c'è di sbagliato? sono su server linux aruba, il codice è:

    Codice PHP:
    <?php

    class ImageComponent extends Object
    {
            function 
    upload_image_and_thumbnail($data$datakey$imgscale$thumbscale$folderName$square) {
            if (
    strlen($data['Image'][$datakey]['name'])>4){ 
                        
    $error 0;
                        
    $tempuploaddir realpath("../../app/webroot/img/temp");
                        
    $biguploaddir realpath("../../app/webroot/img/").'/'.$folderName."/big";
                        
    $smalluploaddir realpath("../../app/webroot/img/").'/'.$folderName."/small";
                        
                        
    // Make sure the required directories exist, and create them if necessary
                        
    if(!is_dir($tempuploaddir)) mkdir($tempuploaddir,true);
                        if(!
    is_dir($biguploaddir)) mkdir($biguploaddir,true);
                        if(!
    is_dir($smalluploaddir)) mkdir($smalluploaddir,true);
                        
                        
    $filetype $this->getFileExtension($data['Image'][$datakey]['name']);
                        
    $filetype strtolower($filetype);
     
                        if ((
    $filetype != "jpeg")  && ($filetype != "jpg") && ($filetype != "gif") && ($filetype != "png") && ($filetype != "tif"))
                        {
                            
    // verify the extension
                            
    return;
                        }
                        
                        
    # convert type
                        
                        
    if ($filetype == "tif") {
                            
                            
    $flagtif true;
                        } else {
                            
    $flagtif false;
                        }
                        
                        
    # -------
                        
                        #$imgsize = GetImageSize($data['Image'][$datakey]['tmp_name']);
                        

                        // Generate a unique name for the image (from the timestamp)
                        
    $id_unic str_replace("."""strtotime ("now"));
                        
    $filename $id_unic;
                          
                        
    settype($filename,"string");
                        
    $filename.= ".";
                        
    $filename.=$filetype;
                        
    $tempfile $tempuploaddir "/$filename";
                        
    $resizedfile $biguploaddir "/$filename";
                        
    $croppedfile $smalluploaddir "/$filename";
                        
                        
    # convert tif in jpg
                                
                        
    if ($flagtif) {
                            
                            if (
    is_uploaded_file($data['Image'][$datakey]['tmp_name'])) {
                                
                                if (
    copy($data['Image'][$datakey]['tmp_name'],"$tempfile")) {
                                    
    $newName preg_replace('#\.tif$#''.jpg'$filename);
                                    require 
    'phmagick/phmagick.php';
                                    
    $p = new phmagick($tempfile$tempuploaddir."/".$newName);
                                    
    $p->debug=true;
                                    
    $p->convert();
                                    
    unlink($tempuploaddir."/".$filename);
                                    
    $filename $newName;
                                    
    $tempfile $tempuploaddir."/".$filename;
                                    
    $resizedfile $biguploaddir "/$filename";
                                    
    $croppedfile $smalluploaddir "/$filename";
                                    
                                }
                            }
                                                
                        } else {
                        
                            if (
    is_uploaded_file($data['Image'][$datakey]['tmp_name']))
                            {                    
                                
    // Copy the image into the temporary directory
                                
    if (!copy($data['Image'][$datakey]['tmp_name'],"$tempfile"))
                                {
                                    print 
    "Error Uploading File!.";
                                    exit(); 
                                }
                         
                            }    
                        }        
                                        
                                
    /*
                                 *    Generate the big version of the image with max of $imgscale in either directions
                                 */
                                 
                                
    $this->resize_img($tempfile$imgscale$resizedfile);                            
                                
                                if(
    $square) {
                                    
    /*
                                     *    Generate the small square version of the image with scale of $thumbscale
                                     */
                                    
    $this->crop_img($tempfile$thumbscale$croppedfile);
                                }
                                else {
                                    
    /*
                                     *    Generate the big version of the image with max of $imgscale in either directions
                                     */
                                    
    $this->resize_img($tempfile$thumbscale$croppedfile);
                                }
                                
                                
    // Delete the temporary image
                                
    unlink($tempfile);
                       
     
                         
    // Image uploaded, return the file name
                         
    return $filename;   
            }
        }
        
        function 
    delete_image($filename,$folderName) {
            
    unlink("../../app/webroot/img/".$folderName."/big/".$filename);
            
    unlink("../../app/webroot/img/".$folderName."/small/".$filename);
        }
        
        function 
    crop_img($imgname$scale$filename) {    
            
    $filetype $this->getFileExtension($imgname);
            
    $filetype strtolower($filetype);
                  
            switch(
    $filetype){
                case 
    "jpeg":
                case 
    "jpg":
                  
    $img_src ImageCreateFromjpeg ($imgname);
                 break;
                 case 
    "gif":
                  
    $img_src imagecreatefromgif ($imgname);
                 break;
                 case 
    "png":
                  
    $img_src imagecreatefrompng ($imgname);
                 break;
            }
            
            
    $width imagesx($img_src);
            
    $height imagesy($img_src);
            
    $ratiox $width $height $scale;
            
    $ratioy $height $width $scale;
             
            
    //-- Calculate resampling
            
    $newheight = ($width <= $height) ? $ratioy $scale;
            
    $newwidth = ($width <= $height) ? $scale $ratiox;
            
            
    //-- Calculate cropping (division by zero)
            
    $cropx = ($newwidth $scale != 0) ? ($newwidth $scale) / 0;
            
    $cropy = ($newheight $scale != 0) ? ($newheight $scale) / 0;
            
            
    //-- Setup Resample & Crop buffers
            
    $resampled imagecreatetruecolor($newwidth$newheight);
            
    $cropped imagecreatetruecolor($scale$scale);
            
            
    //-- Resample
            
    imagecopyresampled($resampled$img_src0000$newwidth$newheight$width$height);
            
    //-- Crop
            
    imagecopy($cropped$resampled00$cropx$cropy$newwidth$newheight);

            
    // Save the cropped image
            
    switch($filetype)
            {
                case 
    "jpeg":
                case 
    "jpg":
                 
    imagejpeg($cropped,$filename,80);
                 break;
                 case 
    "gif":
                 
    imagegif($cropped,$filename,80);
                 break;
                 case 
    "png":
                 
    imagepng($cropped,$filename,80);
                 break;
            }
        }
        
        function 
    resize_img($imgname$size$filename)    {
            
    $filetype $this->getFileExtension($imgname);
            
    $filetype strtolower($filetype);

            switch(
    $filetype) {
                case 
    "jpeg":
                case 
    "jpg":
                
    $img_src ImageCreateFromjpeg ($imgname);
                break;
                case 
    "gif":
                
    $img_src imagecreatefromgif ($imgname);
                break;
                case 
    "png":
                
    $img_src imagecreatefrompng ($imgname);
                break;
            }
            
            
    $true_width imagesx($img_src);
            
    $true_height imagesy($img_src);

            if (
    $true_width>=$true_height)
            {
                
    $width=$size;
                
    $height = ($width/$true_width)*$true_height;
            }
            else
            {
                
    $width=$size;
                
    $height = ($width/$true_width)*$true_height;
            }
            
    $img_des ImageCreateTrueColor($width,$height);
            
    imagecopyresampled ($img_des$img_src0000$width$height$true_width$true_height);

            
    // Save the resized image
            
    switch($filetype)
            {
                case 
    "jpeg":
                case 
    "jpg":
                 
    imagejpeg($img_des,$filename,80);
                 break;
                 case 
    "gif":
                 
    imagegif($img_des,$filename,80);
                 break;
                 case 
    "png":
                 
    imagepng($img_des,$filename,80);
                 break;
            }
        }
     
        function 
    getFileExtension($str) {
     
            
    $i strrpos($str,".");
            if (!
    $i) { return ""; }
            
    $l strlen($str) - $i;
            
    $ext substr($str,$i+1,$l);
            return 
    $ext;
        }
    ?>
    grazie

  2. #2
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    up

  3. #3
    Utente di HTML.it L'avatar di linoma
    Registrato dal
    Mar 2010
    Messaggi
    1,346
    Forse ti crea problemi il parametro 80 (quality) per le PNG è un fattore di compressione tra 0 e 9.
    Per gli Spartani e Sparta usa spartan Il mio github

  4. #4
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    grazie, provo a settarlo a 9 vediamo che succede?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.