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

    Resize di immagini con GD 2 e PHP 4.3.8

    Ciao a tutti, ho un problema con la funziona di ridimensionamento immagini. Con php 4.2.2 e le GD 1.6.2 questa funzione funzionava correttamente... adesso mi crea l'immagine con le nuove dimensioni ma monocromatica...non capisco dove è il problema

    codice:
    function riduci_foto($campo,$dir,$larghezza,$nome){
    	$dest = "/directory/di/destinazione";
    	$img = imagecreatefromjpeg($_FILES[$campo]['tmp_name']);
        	$img_width = imagesx($img);
        	$img_height = imagesy($img);
    	$thumb_width = $larghezza;
    	$thumb_height = ($img_width != $thumb_width) ? floor($thumb_width * $img_height / $img_width) : $img_height;
    	$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
    	imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $img_width, $img_height);
    	imagejpeg($thumb, $dest."/$nome", 100);
    	imagedestroy($img);
    	imagedestroy($thumb);
    }

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2002
    Messaggi
    65
    nessuno ha avuto questo genere di problemi?

  3. #3
    Mi spiegheresti a grandi cenni questa funzione ?
    Ad esempio la variabile $campo che rappresenta ?

  4. #4
    resize_jpg.php
    codice:
    <?php
    if( isSet( $_GET["img"], $_GET["size"] ) ) {
    	$imgSize = getimagesize( (string) $_GET["img"] );
    	$imgX = $imgSize[0];
    	$imgY = $imgSize[1];
    	$newY = floor( ( $imgSize[1] * intval( $_GET["size"] ) ) / $imgSize[0] );
    	header( "Content-type: image/jpg" );
    	$img_original = imageCreateFromJpeg( $_GET["img"] );
    	$img_final = imageCreateTrueColor( $_GET["size"], $newY );
    	imageCopyResampled( $img_final, $img_original, 0, 0, 0, 0, $_GET["size"], $newY, $imgX, $imgY );
    	imageJpeg( $img_final );
    	imageDestroy( $img_original );
    	imageDestroy( $img_final );
    }
    ?>


    file.html
    codice:
    [img]resize_jpg.php?size=80&img=Esempio.jpg[/img]
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  5. #5
    visto che tanto e' una cosa che puo' tornare in generale molto utile, ho fatto una caca-classe in PHP4 compatibile PHP5 e GD2 che fa il resize al volo o crea l'immagine resizata su una cartella in CHMOD 777 .

    Leggi gli esempi e usa il caso 2, quello con la dir specificata, che dovrebbe fare proprio al caso tuo.

    http://andr3a.dotgeek.org/index.php?language=2&class=51

    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

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.