Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 30
  1. #1
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766

    Miniaturizzare le foto del database come anteprima

    Mi sa che il titolo fa un po' schifo pero' ci provo lo stesso.

    Allora, ho dei prodotti inseriti in un database con descrizione, foto, codice, prezzo ecc.
    Nella pagina dove compaiono i titoli, vorrei far comparire una piccola anteprima di immagine alla sinistra del nome del prodotto.
    Come devo fare a pescare la stessa immagine presente nel database e metterla di dimensioni fisse per esempio 60 * 60?
    Mi spiego meglio.
    Andate qua
    Affianco al nome dei prodotti vorrei far comparire l'immagine associata al prodotto in dimensioni ridotte.
    Come posso fare per richiamarla dal database?

  2. #2
    se fossi in te non metterei le immagini direttamente nel database in quanto rischi di rallentare le query e gli altri accessi.
    io una cosa simile l'ho fatta così:
    - memorizzo le foto sul server in una directory.
    - nel database metto il path della foto.
    - così vado bene anche a creare i collegamenti in quanto ho già il path pronto.


    Per l'anteprima la devi creare con delle funzioni della libreria gd2 che devi abilitare in php.



  3. #3
    Utente di HTML.it L'avatar di _kime_
    Registrato dal
    Sep 2003
    Messaggi
    311
    per creare delle miniature avevo trovato questa classe se ti puo' interessare
    Codice PHP:
        /**
        * Thumbnail Class
        *
        * Creates resized (preview-) images
        *
        * Usage Example:
        * $img = new Thumbnail();
        * echo $img->create_tag("../images/photos/sunflower.jpg");
        *
        * @author   Philipp v. Criegern <criegep@criegern.com>
        * @version  1.0 20.02.2002
        */
        
    class Thumbnail
        
    {
            
    /**
            * Directory where the created thumbnails are stored in (for PHP access)
            * e.g. '/usr/local/apache/htdocs/images/thumbnails'
            * Can be overwritten by global configuration array $_CONFIG['thumbnail_dir_internal']
            *
            * @access public
            */
            
    var $thumbnail_dir_internal  =  '';

            
    /**
            * Path to thumbnail directory for browser access
            * e.g. '/images/thumbnails'
            * Can be overwritten by global configuration array $_CONFIG['thumbnail_dir_external']
            *
            * @access public
            */
            
    var $thumbnail_dir_external  =  '';

            
    /**
            * Maximum pixel width of created thumbnail
            *
            * @access public
            */
            
    var $max_width               =  120;

            
    /**
            * Maximum pixel height of created thumbnail
            *
            * @access public
            */
            
    var $max_height              =  120;

            
    /**
            * File name of created thumbnail
            * e.g. 'sunflower.png'
            *
            * @access public
            */
            
    var $image_name;

            
    /**
            * Complete image tag for created thumbnail
            * e.g. '[img]/images/thumbnails/sunflower.png[/img]'
            *
            * @access public
            */
            
    var $image_tag;

            
    /**
            * Error message if creation fails
            *
            * @access public
            */
            
    var $error;

            
    /**
            * Pixel width of created thumbnail
            *
            * @access public
            */
            
    var $width;

            
    /**
            * Pixel height of created thumbnail
            *
            * @access public
            */
            
    var $height;


            
    /**
            * Thumbnail Constructor
            *
            * @access public
            */
            
    function Thumbnail ()
            {
                global 
    $_CONFIG;

                if (!empty(
    $_CONFIG['thumbnail_dir_internal']))
                {
                    
    $this->thumbnail_dir_internal  =  $_CONFIG['thumbnail_dir_internal'];
                }
                if (!empty(
    $_CONFIG['thumbnail_dir_external']))
                {
                    
    $this->thumbnail_dir_external  =  $_CONFIG['thumbnail_dir_external'];
                }
            }

            
    /**
            * Create Thumbnail and return Image Name
            *
            * @access public
            * @param string $parameter Filename of source image
            * @return string Filename of created thumbnail
            */
            
    function create_name $parameter '' )
            {
                
    $this->create$parameter );
                return 
    $this->image_name;
            }

            
    /**
            * Create Thumbnail and return Image Tag
            *
            * @access public
            * @param string $parameter Filename of source image
            * @return string Complete HTML Image-Tag of created thumbnail
            */
            
    function create_tag $parameter '' )
            {
                
    $this->create$parameter );
                return 
    $this->image_tag;
            }

            
    /**
            * Create Thumbnail
            *
            * @access private
            * @param string $parameter Filename of source image
            * @return void
            */
            
    function create $imagefile )
            {
                if (
    strlen($this->thumbnail_dir_internal)  &&  (substr($this->thumbnail_dir_internal, -1) != '/'))
                {
                    
    $this->thumbnail_dir_internal  .=  '/';
                }
                if (
    strlen($this->thumbnail_dir_external)  &&  (substr($this->thumbnail_dir_external, -1) != '/'))
                {
                    
    $this->thumbnail_dir_external  .=  '/';
                }
                
    $tmp_name  =  basename($imagefile);
                if (
    strtolower(substr($tmp_name, -4)) == '.jpg')
                {
                    
    $this->image_name  =  substr($tmp_name0, -4) . '.png';
                    if (!
    is_file($this->thumbnail_dir_internal $this->image_name))
                    {
                        
    $old    =  ImageCreateFromJPEG($imagefile);
                        
    $old_w  =  ImageSX($old);
                        
    $old_h  =  ImageSY($old);
                        
    $this->width   =  $old_w;
                        
    $this->height  =  $old_h;
                        if (
    $this->max_width  &&  ($this->width $this->max_width))
                        {
                            
    $this->height  =  round($this->height $this->max_width $this->width);
                            
    $this->width   =  $this->max_width;
                        }
                        if (
    $this->max_height  &&  ($this->height $this->max_height))
                        {
                            
    $this->width   =  round($this->width $this->max_height $this->height);
                            
    $this->height  =  $this->max_height;
                        }
                        
    $new  =  imagecreate($this->width$this->height);
                        
    imagecopyresized($new$old0,00,0$this->width$this->height$old_w$old_h);
                        
    ImageJPEG($new$this->thumbnail_dir_internal $this->image_name);
                        
    ImageDestroy($new);
                        
    ImageDestroy($old);
                    }
                    else
                    {
                        
    $arr  =  getimagesize($this->thumbnail_dir_internal $this->image_name);
                        
    $this->width   =  $arr[0];
                        
    $this->height  =  $arr[1];
                    }
                    
    $this->image_tag  =  '<IMG SRC="' $this->thumbnail_dir_external $this->image_name 
                                       
    '" WIDTH="'  $this->width
                                       
    '" HEIGHT="' $this->height
                                       
    '" BORDER="0">';
                }
                else
                {
                    
    $this->error  =  "Filetype not JPG";
                }
            }
        } 
    + / Powered by Ubuntu 4.10 "The Warty Warthog"

    + / Manuale PHP.net

    + / Think Free

  4. #4
    puoi usare questa funzione:

    codice:
    function resize ($img="", $thb = "") {
    $src = imagecreatefromjpeg($img); 
    $RealX = imagesx($src);
    $RealY = imagesy($src);
    $maxX = 220;
    $maxY = 170;
    if ($RealX > $maxX) {
    	$newX = $maxX;
    	$newY = ($RealY/$RealX)*$newX;
    	}
    	else
    	{
    	$newY = $maxY;
    	$newX = ($RealX/$RealY)*$newY;
    	}
    
    $dst = imagecreatetruecolor($newX, $newY); 
    imagecopyresized($dst, $src, 0, 0, 0, 0, $newX, $newY, $RealX, $RealY); 
    imagejpeg($dst, $thb, 60); 
    return $dst;
    }

  5. #5
    Io ho fatto qualcosa di simile:
    Codice PHP:
    <?php
    header
    ('Content-Type: image/jpeg');
    $bordo 4;
    $percorso "../../IMG/";
        
    $w $_REQUEST["w"];
        
    $h $_REQUEST["h"];
        
    $img $_REQUEST["img"];
        
        
        
        
    //immagine che farà da bordo + sfondo -->dimensioni $w $h
        
    $im1 = @imagecreatetruecolor($w$h)
           or die(
    "Cannot Initialize new JPG image stream");
        
    imagefilledrectangle($im100$w$himagecolorallocate($im1156180201));
        
    imagefilledrectangle($im1$bordo-1$bordo-1$w-($bordo), $h-($bordo), imagecolorallocate($im1255255255));
        
    $photoImage $im1;
        
    $sourcefile $percorso.$img;
        
    $jpegqual 100;
       
    // Get the dimensions of the source picture
       
    $picsize=getimagesize("$sourcefile");
       
    $source_x  $picsize[0];
       
    $source_y  $picsize[1];
       
    $dest_y $h - (2*$bordo); // nel caso di ==
       
    $dest_x round(($dest_y $source_x) / $source_y);// nel caso di ==
       
    if (($source_x $source_y) < ($w $h)){
               
    $dest_y $h - (2*$bordo);
               
    $dest_x round(($dest_y $source_x) / $source_y);
       }else{
               
    $dest_x $w - (2*$bordo);
                 
    $dest_y round(($dest_x $source_y) / $source_x);
       }
        switch (
    $picsize[2]){
            case 
    1//gif
                
    $source_id imageCreateFromGIF("$sourcefile");
            break;
            case 
    2//jpeg
                
    $source_id imageCreateFromJPEG("$sourcefile");
            break;
            case 
    3// png
                
    $source_id imageCreateFromPNG("$sourcefile");
            break;
            case 
    4//swf
                
    ;//errore
            
    break;
            case 
    5//psd
                
    ;//errore
            
    break;
            case 
    6//bmp
                
    $source_id imagecreatefromwbmp("$sourcefile");
            break;
            case 
    7//TIFF_II (intel byte order)
                
    ;//errore
            
    break;
            case 
    8//TIFF_MM (motorola byte order)
                
    ;//errore
            
    break;
            case 
    9//jpc
                
    ;//errore
            
    break;
            case 
    10//jp2
                
    ;//errore
            
    break;
            case 
    11//jpx
                
    ;//errore
            
    break;
            case 
    12//jb2
                
    ;//errore
            
    break;
            case 
    13//swc
                
    ;//errore
            
    break;
            case 
    14//iff
                
    ;//errore
            
    break;
            case 
    15//wbmp
                
    ;//errore
            
    break;
            case 
    16//xbm
                
    ;//errore
            
    break;
            default:
                 
    $source_id imageCreateFromJPEG("$sourcefile");//vado a muzzo e gli faccio generare l'errore...
        
    }
        
    // Create a new image object (not neccessarily true colour) 
        
    $target_id=imagecreatetruecolor($dest_x$dest_y);
        
    // Resize the original picture and copy it into the just created image
        // object. Because of the lack of space I had to wrap the parameters to
        // several lines. I recommend putting them in one line in order keep your
        // code clean and readable 
        
    $target_pic=imagecopyresampled($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
        
    // Create a jpeg with the quality of "$jpegqual" out of the
        // image object "$target_pic".
        // This will be saved as $targetfile 
        
    $imgFinale $target_id;
        
    $posX round(($w $dest_x)/2);
        
    $posY round(($h $dest_y)/2);
        
    //unisco lo sfondo bordato e la fotografia -->dimensione $w $h
        
    $targetfile $percorso."show_".$img;
        
    $jpegqual 100;
        
    ImageAlphaBlending($photoImagetrue);
        
    $logoImage $imgFinale;
        
    $logoW ImageSX($logoImage);
        
    $logoH ImageSY($logoImage);
        
    ImageCopy($photoImage$logoImage$posX$posY00$logoW$logoH);
        
        
    ImageJPEG($photoImage);
        
    imagedestroy($photoImage);
        
    imagedestroy($logoImage);
        
    imagedestroy($im1);
        
    imagedestroy($im2);
        
    imagedestroy($target_id);
        
    imagedestroy($source_id);
    ?>

    Spiego un po':
    tu metti questo codice in una pagina (image.php per esempio)
    quando devi stampare a video un'immagine fai così:
    [img]image.php?w=<? echo $w; ?>&h=<? echo $h; ?>&img=<? echo $img; ?>[/img]" height="<? echo $h; ?>">

    dove $w è la larghezza, $h l'altezza e $img il nome dell'immagine

    In pratica ridimensiona l'immagine sorgente in modo da farcela stare in un'altra immagine delle dimesnioni che desideri tu, aggiungendo anche un bordo.
    Modificando il codice puoi ottenere quello che vuoi.

    Potrebbero esserci dei bug in quanto il metodo che uso lo sto sperimentando e quindi è ancora in costante aggiornamento, cmq lo sto usando e funziona correttamente.

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    87
    Io mi sono trovato nelle tue stesse condizioni e ho fatto così :

    quando aggiungo un prodotto con immagine al database lo script fa l'upload dell'immagine sull'ftp e si crea la thumbnail. Poi nel database memorizzo solo il nome dell'immagine. In questo modo non devo fargli creare le thumb ogni volta che l'utente visualizza la pagina con i prodotti, altrimenti credo che il carico per il server, con le gd che processano magari 30-40 immagini (supponendo che il catalogo sia paginato), diventerebbe eccessivo credo.

    Usa questa classe : dropshadow

    Ciao

  7. #7
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    Grazie per le risposte raga', cmq le immagini vengono copiate in una cartella del sito e nel database c'e' solo il nome dell'immagine associata.
    Gli esempi che mi avete postato vanno bene lo stess??

  8. #8
    certamente.
    anche io ho fatto come te.
    Quando fai il resizing dell'immagine non ti interessa il DB.
    Sarai tu che poi dovrai fare una query di INSERT e specificare il path dell'anteprima.

  9. #9
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    Originariamente inviato da luqwe
    certamente.
    anche io ho fatto come te.
    Quando fai il resizing dell'immagine non ti interessa il DB.
    Sarai tu che poi dovrai fare una query di INSERT e specificare il path dell'anteprima.
    per visualizzare l'immagine devo mettere questo codice:
    Codice PHP:
    <? if($foto==null){echo "<font face='Arial, Verdana, serif' size=2 color=#FFFFFF>Anteprima non disponibile</font>";}else{echo "[img]fotoschede/$foto[/img]";}?>
    o no?

  10. #10
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    mi da errore in questa stringa:
    Codice PHP:
    "[*]echo "[img]fotoschede/$foto[/img]"<a href=\"ceramica.php?id=$id\">$prodotto</a>"
    dove sbaglio?
    In pratica voglio dire che deve mostrare prima l'immagine e poi subito dopo il nome del prodotto con il relativo link...

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.