Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    111

    [PHP] Immagini thumbnail brutte...

    Salve a tutti, ho scaricato dagli script di php un programmino per creare al volo delle png da jpeg (tnp.php). Funziona bene, ma l'aspetto delle thumbnail è orribile, perde qualsiasi colore, non mantenedo i colori originali delle jpeg.

    Qualcuno sa darmi una mano su dove intervenire?

    GRAZIE.

    Codice PHP:
    <?
    if (!isset($image)){ // if not generate an error image
        
    $img ImageCreate(100100);
        
    $red ImageColorAllocate($img25500);
        
    $yellow ImageColorAllocate($img2552550);
        
    ImageString($img52020"No image"$yellow);
        
    ImageString($img52040"name"$yellow);
        
    ImageString($img52060"given!"$yellow);
        
    ImagePNG($img);
        
    ImageDestroy($img);
        exit();
    }
    // check if the 'tnsize' parameter has been given
    if (!isset($tnsize)) { // if not generate an error image
        
    $img ImageCreate(100100);
        
    $red ImageColorAllocate($img25500);
        
    $yellow ImageColorAllocate($img2552550);
        
    ImageString($img52020"No thumb"$yellow);
        
    ImageString($img52040"size"$yellow);
        
    ImageString($img52060"given!"$yellow);
        
    ImagePNG($img);
        
    ImageDestroy($img);
        exit();
    }
    // ensure that $tnsize is an integer 
    $tnsize = (integer) $tnsize;
    // check that the size asked for is sensible
    if (($tnsize<20) or ($tnsize>300)){ // if not generate an error image
        
    $img ImageCreate(100100);
        
    $red ImageColorAllocate($img25500);
        
    $yellow ImageColorAllocate($img2552550);
        
    ImageString($img52020"Bad"$yellow);
        
    ImageString($img52040"size"$yellow);
        
    ImageString($img52060"given!"$yellow);
        
    ImagePNG($img);
        
    ImageDestroy($img);
        exit();
    }
    // attempt to load the big image
    if (!$bigimage = @ImageCreateFromJPEG($image)) {    // if loading fails
        
    $img ImageCreate(100100);                    // generate an error
        
    $red ImageColorAllocate($img25500);        // image
        
    $yellow ImageColorAllocate($img2552550);
        
    ImageString($img52020"Image"$yellow);
        
    ImageString($img52040"not"$yellow);
        
    ImageString($img52060"found!"$yellow);
        
    ImagePNG($img);
        
    ImageDestroy($img);
        exit();
    }
    $tnimage ImageCreate($tnsize$tnsize);
    $darkblue ImageColorAllocate($tnimage00127);
    ImageColorTransparent($tnimage,$darkblue);
    $sz GetImageSize($image);
    $x $sz[0];    // big image width
    $y $sz[1];    // big image height
    if ($x>$y) {    // if it is the width then
        
    $dx 0;                    // the left side of the new image
        
    $w $tnsize;                // the width of the new image
        
    $h = ($y $x) * $tnsize;    // the height of the new image
        
    $dy = ($tnsize $h) / 2;    // the top of the new image
    }else{    // if the height is larger then
        
    $dy 0;                    // the top of the new image
        
    $h $tnsize;                // the height of the new image
        
    $w = ($x $y) * $tnsize;    // the width of the new image
        
    $dx = ($tnsize $w) / 2;    // the left edgeof the new image
    }
    ImageCopyResized($tnimage$bigimage$dx$dy00$w$h$x$y);
    ImagePNG($tnimage);
    ImageDestroy($tnimage);
    ImageDestroy($bigimage);
    // all done!
    ?>

  2. #2
    Hai provato con ImageCreateTrueColor invece che ImageCreate?
    "Le uniche cose che sbagli sono quelle che non provi a fare."
    Atipica

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    111
    grazie, ci provo!

  4. #4
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    111
    Con il truecolor va decisamente meglio, ma non è come la foto grande... perde sempre in nitidezza. E' normale o devo usare altre funzioni?

    Grazie.

  5. #5
    Beh, diminuendo il numero di pixel è chiaro che perdi in nitidezza; comunque prova a guardare nei parametri di ImageCopyResized.

    Ciao!
    "Le uniche cose che sbagli sono quelle che non provi a fare."
    Atipica

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.