Visualizzazione dei risultati da 1 a 5 su 5

Discussione: resize di immagini jpg

  1. #1
    Utente di HTML.it L'avatar di Xevion
    Registrato dal
    Sep 2003
    Messaggi
    48

    resize di immagini jpg

    ciao avrei bisogno di sapere come e se è possibile ridimensionare un immagine senza utilizzare le librerie gd2. Anche se è possibile ridimensionare solo il formato jpeg va benissimo grazie mille ciao ciao
    Il secondo è il primo degli ultimi diamoci dentro

  2. #2
    Utente di HTML.it L'avatar di _kime_
    Registrato dal
    Sep 2003
    Messaggi
    311
    se è questo a cui ti riferisci...ecco cosa avevo trovato
    Codice PHP:
    <?
        
    /*
        * $img = new Thumbnail();
        * echo $img->create_tag("../images/photos/sunflower.jpg");
        */
        
    class Thumbnail
        
    {
            
    /*
            * e.g. '/usr/local/apache/htdocs/images/thumbnails'
            */
            
    var $thumbnail_dir_internal  =  '';

            
    /*
            * e.g. '/images/thumbnails'
            */
            
    var $thumbnail_dir_external  =  '';

            
    // Larghezza & Altezza
            
    var $max_width               =  120;
            var 
    $max_height              =  120;
            
            var 
    $image_name;
            var 
    $image_tag;
            var 
    $error;
            var 
    $width;
            var 
    $height;


            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'];
                }
            }

            function 
    create_name $parameter '' )
            {
                
    $this->create$parameter );
                return 
    $this->image_name;
            }

            function 
    create_tag $parameter '' )
            {
                
    $this->create$parameter );
                return 
    $this->image_tag;
            }

            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

  3. #3
    Ho posto anche io la stessa domanda tempo fa e mi hanno detto che l'unico modo è utilizzare le GD. Altrimenti prova a vedere qui:
    http://www.php.net/manual/it/ref.image.php

    Io non mi ci sono soffermato molto: per me è stato più veloce installare le GD. Ciao!
    eCommerceRS.NET - Commerciante, vendi on-line!
    Il mio nick è mircov e non mirco!!!

  4. #4
    Utente di HTML.it L'avatar di Xevion
    Registrato dal
    Sep 2003
    Messaggi
    48
    ok grazie proverò il codice che mi hai scritto comunque non credo che per quello che mi serve possa andare bene perchè io devo ridimensionare l'immagine che l'utente inserisce tramite form ma prima che mi venga caricata su server.
    Il secondo è il primo degli ultimi diamoci dentro

  5. #5
    NO, non lo puoi fare in alcun modo!
    Quando carichi un immagine e vuoi ridimensionarla funziona così:

    Se non devi modificare l'immagine
    1) La carichi nella cartella temporanea
    2) La sposti nella tua cartella

    Se ci devi fare delle operazioni (tipo resizing)
    1) Carichi nella cartella temporanea
    2) Ci fai le operazioni che ci devi fare
    3) Salvi la nuova versione nella tua cartella
    4) Cancelli l'immagine sorgente nella cartella temporanea del server
    eCommerceRS.NET - Commerciante, vendi on-line!
    Il mio nick è mircov e non mirco!!!

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.