Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    16

    problema con funzione che ridimensiona immagini

    Ciao a tutti,
    ho un problema con questa funzione che carica in una cartella temporanea un immagine passata tramite un form e che successivamente la ridimensiona mantenendo le proporzioni.
    La funzione si comporta correttamente fino a quando memorizza nella directory temporanea l'immagine, poi non succede nulla e soprattutto non mi da un errore.... ecco il codice:

    <?php

    function upload_image($attach,$file_name,$file_type){
    if (is_uploaded_file($attach)) {



    if( $file_type == "image/jpeg" || $file_type == "image/gif" || $file_type == "image/jpg"){
    if (file_exists('upload_image_temp/'.$file_name)) {
    return false;
    }
    if (!move_uploaded_file($attach, 'upload_image_temp/'.$file_name)) {
    return false;
    }

    if( $file_type == "image/jpeg" || $file_type == "image/jpg"){
    $path_to_img="upload_image_temp/".$file_name;
    //$imagehw = getimagesize("upload_image_temp/".$file_name);
    list($width, $height) = getimagesize($path_to_img);
    $final_width=150;
    $final_height=(150*$width)/$height;
    $dst_img=@imagecreatetruecolor(final_width,$final_ height);
    $src_img=@imagecreatefromjpeg("$path_to_img");
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $final_width, $final_height, $width, $height);
    imagejpeg($dst_img,"upload_image".$file_name,90);
    unlink ("upload_image_temp/"."$file_name");
    return true;
    }

    if( $file_type == "image/png"){
    $path_to_img="upload_image_temp/".$file_name;
    $imagehw = getimagesize($path_to_img);
    $final_width=150;
    $final_height=(150*$imagehw[1])/$imagehw[0];
    $dst_img=@imagecreatetruecolor(final_width,$final_ height);
    $src_img=@imagecreatefrompng($path_to_img);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$fina l_width,$final_height,ImageSX($src_img),ImageSY($s rc_img));
    imagepng($dst_img,"upload_image".$file_name,90);
    unlink ("upload_image_temp/".$file_name);
    return true;
    }

    return true;
    }
    else{
    return false;
    }

    }
    }




    ?>



    aspetto con ansia una vostra risposta.

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    542

    Ridimensionamento immagine

    Ciao,
    tempo fa ho avuto un problema simile ed ho risolto così:

    Codice PHP:

    ... codice upload file

    ' ridimensionamento immagine:
    $larghezza=200; 
    $altezza=180;
    if (resizeImage($fileupload_temp, $target_path, $larghezza, $altezza)) { 
        $ret=true; }
    else { 
        return false;
    }

    // se lavora con file uploaded by remoto
    // riceve come parametro $imgIn: $_FILES['
    image']['tmp_name']
    function resizeImage($imgIn, $imgOut, $larghezza, $altezza)
    {
        // Ottengo le informazioni sull'
    immagine originale
        
    list($width$height$type$attr) = getimagesize($imgIn);
        
        
    // Crea la versione $larghezza*$altezza dell'immagine
        
    $thumb imagecreatetruecolor($larghezza$altezza);
        
    $source imagecreatefromjpeg($imgIn);
        
    imagecopyresized($thumb$source0000$larghezza$altezza$width$height);
        
        
    // Salva immagine ridimensionata
        // parametro qualità 1-100, ottimale 65-85, predefinito 75.
        
    return imagejpeg($thumb$imgOut75);


    Parte di questo codice l'ho trovato in rete.
    Spero possa aiutarti.

    Ciao
    Guidino

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    16
    Ciao,
    grazie dell'aiuto ma io dovrei ridimensionare le immagini mantenendo le proporzioni e in quel codice la larghezza e l'altezza vengono passati di default... vabbe ciao e grazie di nuovo.

  4. #4
    Che errore ti da?
    Antonio Correnti
    www.resetstudio.it

  5. #5
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    16
    nessuno...

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 © 2025 vBulletin Solutions, Inc. All rights reserved.