Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di diaz
    Registrato dal
    Apr 2000
    residenza
    Berlin
    Messaggi
    379

    resize immagine da mysql blob

    ho fatto uno script che dovrebbe ridimensionare e visualizzare delle immagini salvate in campo blob di mysql, ma purtroppo mi da errore in quanto non riesce a trovare il file da ridimensionare

    codice:
    ... getimagesize(ÿØÿà): failed to open stream: No such file or directory in ...
    il codice è questo


    codice:
    	$tmp_name = $row['immagine'];
    
    	list( $width, $height, $type ) = getimagesize( $tmp_name );
    	$new_width = 50;
    	$new_height = $height / $width * $new_width;
    	if ($type == 1)
    		$src_img = imagecreatefromgif( $tmp_name );
    	if ($type == 2)
    		$src_img = imagecreatefromjpeg( $tmp_name );
    	elseif ($type == 3)
    		$src_img = imagecreatefrompng( $tmp_name );	
    	$im = Imagecreatetruecolor( $new_width, $new_height );
    	imagecopyresampled( $im, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    	ob_start();
    	imagejpeg( $im );
    	imagedestroy( $im );
    	$data = ob_get_clean();
    	$data = addslashes( $data );
    }
    
    
    
    
    
    header('Content-Type: image/jpeg');
    echo  $data;
    E da quel giorno, se andavo da qualche parte, io ci andavo correndo!

    Tweeting @apphancer | Views my own – except when I say things I don’t really think.

  2. #2
    tempo fa per fare una cosa simile salvavo il contenuto del campo blob in un file temporaneo e lo davo in pasto alle gd...

  3. #3
    Utente di HTML.it L'avatar di diaz
    Registrato dal
    Apr 2000
    residenza
    Berlin
    Messaggi
    379
    ci ho lavorato molto ma non riesco a farlo funzionare
    penso che vada tutto bene tranne che l'impostazione del content-type, perchè se lo setto a image/jpeg mi stampa a video la url dello script, se invece lo tolgo mi visualizza tutti caratteri strani

    posto qui il codice:

    codice:
    <?php
    
    include("../config.inc.php");
    $query = "SELECT * FROM prodotti WHERE id_prodotto LIKE '$id'";                                                                                                       
    $result = mysql_query($query) or die('Query non valida: ' . mysql_error()); 
    $row = mysql_fetch_array($result);  
        
    
    
       // creazione di un nome di immagine temporeno
       $t_img_name = tempnam ("/tmp", "timg");
       $t_img = fopen($t_img_name, "w");
    
       // $content è il campo blob che contiene l'immagine
       fwrite($t_img, $row['immagine']);
       fclose($t_img);
    
       // qui eseguto operazioni sull'immagine
       list( $width, $height, $type ) = getimagesize( $t_img_name );
       $new_width = 150;
       $new_height = $height / $width * $new_width;
       if ($type == 1)
    		$src_img = imagecreatefromgif( $t_img_name );
    	if ($type == 2)
    		$src_img = imagecreatefromjpeg( $t_img_name );
    	elseif ($type == 3)
    		$src_img = imagecreatefrompng( $t_img_name );	
    	$im = Imagecreatetruecolor( $new_width, $new_height );
    	imagecopyresampled( $im, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    	ob_start();
    	imagejpeg( $im );
    	imagedestroy( $im );
    	$data = ob_get_clean();
    	$data = addslashes( $data );
    
    
     
    header('Content-Type: image/jpeg');
    echo  $data;
    
    
    
       // cancello il file temporaneo creato
       unlink($t_img_name); 
    
                 
    mysql_close($db);
    ?>
    E da quel giorno, se andavo da qualche parte, io ci andavo correndo!

    Tweeting @apphancer | Views my own – except when I say things I don’t really think.

  4. #4
    addirittura togliendo tutta la parte che effettua il ridemensionamento non va


    codice:
    $t_img_name = tempnam ("/tmp", "timg");
    $t_img = fopen($t_img_name, "w");
    
    fwrite($t_img, $row['immagine']);
    
    fclose($t_img);
    
    $size = getimagesize($t_img_name);   
    
    header("Content-Type: image/jpeg");   
    echo $t_img_name;

  5. #5
    risolto! e mi sembra giusto lasciare disponibile la soluzione per i posteri


    Codice PHP:
    <?php

    // variabili definite dalla pagina che richiama lo script
    // es. immagine.php?id=8&width=150
    $id $_GET["id"];
    $wid $_GET["width"];

    include(
    "../config.inc.php"); 

    // Esegui la query
    $query "SELECT * FROM prodotti WHERE id_prodotto LIKE '$id'";                                                                                                       
    $result mysql_query($query) or die('Query non valida: ' mysql_error()); 
    $row mysql_fetch_array($result);  
        

    // Creazione dell'immagine temporanea
        
    $t_img_name tempnam ("/tmp""timg");
        
    $t_img fopen($t_img_name"w");

    // $row['immagine'] è il campo blob del database
        
    fwrite($t_img$row['immagine']);
        
    fclose($t_img);

    // Qui eseguo le modifiche desiderate sull'immagine
    Header("Content-type: image/jpeg");
        list( 
    $width$height$type ) = getimagesize$t_img_name );
        
    $new_width $wid;
        
    $new_height $height $width $new_width;
        if (
    $type == 1$src_img imagecreatefromgif$t_img_name );
        if (
    $type == 2)    $src_img imagecreatefromjpeg$t_img_name );
        elseif (
    $type == 3)    $src_img imagecreatefrompng$t_img_name );    
        
    $im Imagecreatetruecolor$new_width$new_height );
        
    imagecopyresampled$im$src_img0000$new_width$new_height$width$height);

        
    Imagejpeg($im,'',95);
        
    ImageDestroy($im); 

    // cancello il file temporaneo creato
       
    unlink($t_img_name); 
                 
    mysql_close($db);
    ?>

  6. #6
    A me non va, anche la tua soluzione funzionante... mi stampa a video, come immagine, l'url dell'immagine ma non la carica mica... non capisco perchè!! La cartella /tmp l'ho creata, con permessi 777...

    Codice PHP:
    <?php

    // variabili definite dalla pagina che richiama lo script
    // es. immagine.php?id=8&width=150
    $id $_GET["id"];
    $wid $_GET["width"];

    include(
    "config.php");

    // Esegui la query
    $query "SELECT id,type,immagine FROM immagini WHERE id LIKE '$id'";                                                                                                       
    $result mysql_query($query) or die('Query non valida: ' mysql_error());
    $row mysql_fetch_array($result);  
        

    // Creazione dell'immagine temporanea
        
    $t_img_name tempnam ("/tmp""timg");
        
    $t_img fopen($t_img_name"w");

    // $row['immagine'] è il campo blob del database
        
    fwrite($t_img$row['immagine']);
        
    fclose($t_img);

    // Qui eseguo le modifiche desiderate sull'immagine
    header("Content-type: image/jpeg");
        list( 
    $width$height$type ) = getimagesize$t_img_name );
        
    $new_width $wid;
        
    $new_height $height $width $new_width;
        if (
    $type == 1$src_img imagecreatefromgif$t_img_name );
        if (
    $type == 2)    $src_img imagecreatefromjpeg$t_img_name );
        elseif (
    $type == 3)    $src_img imagecreatefrompng$t_img_name );    
        
    $im Imagecreatetruecolor$new_width$new_height );
        
    imagecopyresampled$im$src_img0000$new_width$new_height$width$height);

        
    Imagejpeg($im,'',95);
        
    ImageDestroy($im);

    // cancello il file temporaneo creato
       
    unlink($t_img_name);
                 
    mysql_close($db);
    ?>
    "Quando uno è fatto così, è fatto per la roba"
    G.Verga - "La Roba"

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.